Skip to content

Commit

Permalink
Optimization for jsonFromStrInternal().
Browse files Browse the repository at this point in the history
This is an extremely hot code path when saving the manifest so every little bit helps.
  • Loading branch information
dwsteele committed Jan 22, 2022
1 parent 61ce586 commit ca13f11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/xml/release.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<commit subject="Simplify manifest defaults."/>
<commit subject="Convert varNewUInt64() to VARUINT64() where possible in manifest."/>
<commit subject="Pack manifest file structs to save memory."/>
<commit subject="Optimization for jsonFromStrInternal()."/>

<release-item-contributor-list>
<release-item-contributor id="david.steele"/>
Expand Down
11 changes: 6 additions & 5 deletions src/common/type/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,14 +682,13 @@ jsonFromStrInternal(String *json, const String *string)
strCatChr(json, '"');

// Track portion of string with no escapes
const char *stringPtr = strZ(string);
const char *noEscape = NULL;
size_t noEscapeSize = 0;

for (unsigned int stringIdx = 0; stringIdx < strSize(string); stringIdx++)
{
char stringChr = strZ(string)[stringIdx];

switch (stringChr)
switch (*stringPtr)
{
case '"':
case '\\':
Expand All @@ -706,7 +705,7 @@ jsonFromStrInternal(String *json, const String *string)
noEscapeSize = 0;
}

switch (stringChr)
switch (*stringPtr)
{
case '"':
strCatZ(json, "\\\"");
Expand Down Expand Up @@ -744,12 +743,14 @@ jsonFromStrInternal(String *json, const String *string)
{
// If escape string is zero size then start it
if (noEscapeSize == 0)
noEscape = strZ(string) + stringIdx;
noEscape = stringPtr;

noEscapeSize++;
break;
}
}

stringPtr++;
}

// Copy portion of string without escapes
Expand Down

0 comments on commit ca13f11

Please sign in to comment.