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="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"/>

View File

@ -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 '\\':
@ -706,7 +705,7 @@ jsonFromStrInternal(String *json, const String *string)
noEscapeSize = 0;
}
switch (stringChr)
switch (*stringPtr)
{
case '"':
strCatZ(json, "\\\"");
@ -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