Skip to content

Commit

Permalink
json: Optimize memory usage by not collecting string values
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
b4n committed Jan 31, 2015
1 parent 2ff1386 commit 0bd9585
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tagmanager/ctags/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 0bd9585

Please sign in to comment.