1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Optimization for jsonFromStrInternal().

This is an extremely hot code path when saving the manifest so every little bit helps.
This commit is contained in:
David Steele 2022-01-22 17:20:25 -05:00
parent 61ce58692f
commit ca13f11b4a
2 changed files with 7 additions and 5 deletions

View File

@ -69,6 +69,7 @@
<commit subject="Simplify manifest defaults."/> <commit subject="Simplify manifest defaults."/>
<commit subject="Convert varNewUInt64() to VARUINT64() where possible in manifest."/> <commit subject="Convert varNewUInt64() to VARUINT64() where possible in manifest."/>
<commit subject="Pack manifest file structs to save memory."/> <commit subject="Pack manifest file structs to save memory."/>
<commit subject="Optimization for jsonFromStrInternal()."/>
<release-item-contributor-list> <release-item-contributor-list>
<release-item-contributor id="david.steele"/> <release-item-contributor id="david.steele"/>

View File

@ -682,14 +682,13 @@ jsonFromStrInternal(String *json, const String *string)
strCatChr(json, '"'); strCatChr(json, '"');
// Track portion of string with no escapes // Track portion of string with no escapes
const char *stringPtr = strZ(string);
const char *noEscape = NULL; const char *noEscape = NULL;
size_t noEscapeSize = 0; size_t noEscapeSize = 0;
for (unsigned int stringIdx = 0; stringIdx < strSize(string); stringIdx++) for (unsigned int stringIdx = 0; stringIdx < strSize(string); stringIdx++)
{ {
char stringChr = strZ(string)[stringIdx]; switch (*stringPtr)
switch (stringChr)
{ {
case '"': case '"':
case '\\': case '\\':
@ -706,7 +705,7 @@ jsonFromStrInternal(String *json, const String *string)
noEscapeSize = 0; noEscapeSize = 0;
} }
switch (stringChr) switch (*stringPtr)
{ {
case '"': case '"':
strCatZ(json, "\\\""); strCatZ(json, "\\\"");
@ -744,12 +743,14 @@ jsonFromStrInternal(String *json, const String *string)
{ {
// If escape string is zero size then start it // If escape string is zero size then start it
if (noEscapeSize == 0) if (noEscapeSize == 0)
noEscape = strZ(string) + stringIdx; noEscape = stringPtr;
noEscapeSize++; noEscapeSize++;
break; break;
} }
} }
stringPtr++;
} }
// Copy portion of string without escapes // Copy portion of string without escapes