From 0bd95857041091a3d17d2c728ac0a69c8ea04c52 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Fri, 28 Nov 2014 16:46:39 +0100 Subject: [PATCH] json: Optimize memory usage by not collecting string values When a string is not used as an object property the parser doesn't need to know its value. Not collecting it into memory lowers memory consumption and avoids high memory consumption with huge string values. --- tagmanager/ctags/json.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tagmanager/ctags/json.c b/tagmanager/ctags/json.c index 49f5d2cef..553c0a4d0 100644 --- a/tagmanager/ctags/json.c +++ b/tagmanager/ctags/json.c @@ -138,7 +138,8 @@ static boolean isIdentChar (int c) return (isalnum (c) || c == '+' || c == '-' || c == '.'); } -static void readToken (tokenInfo *const token) +static void readTokenFull (tokenInfo *const token, + boolean includeStringRepr) { int c; @@ -178,7 +179,8 @@ static void readToken (tokenInfo *const token) break; /* break on invalid, unescaped, control characters */ else if (c == '"' || c == EOF) break; - vStringPut (token->string, c); + if (includeStringRepr) + vStringPut (token->string, c); } vStringTerminate (token->string); break; @@ -209,6 +211,8 @@ static void readToken (tokenInfo *const token) } } +#define readToken(t) (readTokenFull ((t), FALSE)) + static void pushScope (tokenInfo *const token, const tokenInfo *const parent, const jsonKind parentKind) @@ -287,7 +291,7 @@ static void parseValue (tokenInfo *const token) do { - readToken (token); + readTokenFull (token, TRUE); if (token->type == TOKEN_STRING) { jsonKind tagKind = TAG_NULL; /* default in case of invalid value */ -- 2.11.4.GIT