Performance optimization in jsonAppendString().
FossilOrigin-Name: fdf00e96239c73fb67e2acecc5b95f55a1fc51c3deed4512613c0d6070ce5805
This commit is contained in:
parent
679c90850c
commit
f0b8b16317
12
manifest
12
manifest
@ -1,5 +1,5 @@
|
||||
C Simplification\sand\soptimization\sof\sthe\sJSON\sparser.
|
||||
D 2023-12-02T13:36:52.119
|
||||
C Performance\soptimization\sin\sjsonAppendString().
|
||||
D 2023-12-02T14:16:47.613
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -688,7 +688,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
|
||||
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
|
||||
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
|
||||
F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
|
||||
F src/json.c 73558b9dca8f326045c42350bd8274c9a9a6489cdb145b2208a8fc7e50a04247
|
||||
F src/json.c a3eabd185cfd13250503ac8a17ac3ec61c9bb88730f99134de9df6c9a3446d46
|
||||
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
||||
F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
|
||||
F src/main.c 1b89f3de98d1b59fec5bac1d66d6ece21f703821b8eaa0d53d9604c35309f6f9
|
||||
@ -2145,8 +2145,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P a6dc29e4d5e13949e0fcd9d5dde575c2670eb10a230ab9df3806fc8c3016c540
|
||||
R d65ba1fc2a2f76e7b171a7dc72bb1070
|
||||
P f5ec9485119a2a6cb33eb864c7ca9b41d4a2ed08ab6ad9a6b0dd9358ab253576
|
||||
R a5df9ac2834f12883789ae2220af8e65
|
||||
U drh
|
||||
Z b0de3fe3c23565cae5077bfe62fcd8b8
|
||||
Z f68f81753669c00bcaaaadfbdd6d3188
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
f5ec9485119a2a6cb33eb864c7ca9b41d4a2ed08ab6ad9a6b0dd9358ab253576
|
||||
fdf00e96239c73fb67e2acecc5b95f55a1fc51c3deed4512613c0d6070ce5805
|
36
src/json.c
36
src/json.c
@ -595,17 +595,33 @@ static void jsonAppendSeparator(JsonString *p){
|
||||
** string.
|
||||
*/
|
||||
static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
|
||||
u32 i;
|
||||
if( zIn==0 ) return;
|
||||
u32 k;
|
||||
u8 c;
|
||||
const u8 *z = (const u8*)zIn;
|
||||
if( z==0 ) return;
|
||||
if( (N+p->nUsed+2 >= p->nAlloc) && jsonStringGrow(p,N+2)!=0 ) return;
|
||||
p->zBuf[p->nUsed++] = '"';
|
||||
for(i=0; i<N; i++){
|
||||
unsigned char c = ((unsigned const char*)zIn)[i];
|
||||
if( jsonIsOk[c] ){
|
||||
p->zBuf[p->nUsed++] = c;
|
||||
}else if( c=='"' || c=='\\' ){
|
||||
while( 1 /*exit-by-break*/ ){
|
||||
k = 0;
|
||||
while( k<N-1 && jsonIsOk[z[k]] && jsonIsOk[z[k+1]] ){ k += 2; }
|
||||
while( k<N && jsonIsOk[z[k]] ){ k++; }
|
||||
if( k>=N ){
|
||||
if( k>0 ){
|
||||
memcpy(&p->zBuf[p->nUsed], z, k);
|
||||
p->nUsed += k;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if( k>0 ){
|
||||
memcpy(&p->zBuf[p->nUsed], z, k);
|
||||
p->nUsed += k;
|
||||
z += k;
|
||||
N -= k;
|
||||
}
|
||||
c = z[0];
|
||||
if( c=='"' || c=='\\' ){
|
||||
json_simple_escape:
|
||||
if( (p->nUsed+N+3-i > p->nAlloc) && jsonStringGrow(p,N+3-i)!=0 ) return;
|
||||
if( (p->nUsed+N+3 > p->nAlloc) && jsonStringGrow(p,N+3)!=0 ) return;
|
||||
p->zBuf[p->nUsed++] = '\\';
|
||||
p->zBuf[p->nUsed++] = c;
|
||||
}else if( c=='\'' ){
|
||||
@ -626,7 +642,7 @@ static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
|
||||
c = aSpecial[c];
|
||||
goto json_simple_escape;
|
||||
}
|
||||
if( (p->nUsed+N+7+i > p->nAlloc) && jsonStringGrow(p,N+7-i)!=0 ) return;
|
||||
if( (p->nUsed+N+7 > p->nAlloc) && jsonStringGrow(p,N+7)!=0 ) return;
|
||||
p->zBuf[p->nUsed++] = '\\';
|
||||
p->zBuf[p->nUsed++] = 'u';
|
||||
p->zBuf[p->nUsed++] = '0';
|
||||
@ -634,6 +650,8 @@ static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
|
||||
p->zBuf[p->nUsed++] = "0123456789abcdef"[c>>4];
|
||||
p->zBuf[p->nUsed++] = "0123456789abcdef"[c&0xf];
|
||||
}
|
||||
z++;
|
||||
N--;
|
||||
}
|
||||
p->zBuf[p->nUsed++] = '"';
|
||||
assert( p->nUsed<p->nAlloc );
|
||||
|
Loading…
Reference in New Issue
Block a user