Faster implementation of numberic literal parsing in JSON.

FossilOrigin-Name: 58398292e8473b0b9e4b77dd5ed27334bc24a85d0c399e8d0b86de6fb59dadce
This commit is contained in:
drh 2023-04-27 19:13:20 +00:00
parent 49d8e0ef97
commit 1371df2117
3 changed files with 31 additions and 27 deletions

View File

@ -1,5 +1,5 @@
C Add\ssupport\sfor\shexadecimal\sinteger\sliterals\sin\sJSON.
D 2023-04-27T18:28:10.882
C Faster\simplementation\sof\snumberic\sliteral\sparsing\sin\sJSON.
D 2023-04-27T19:13:20.680
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -592,7 +592,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h b638809e083b601b618df877b2e89cb87c2a47a01f4def10be4c4ebb54664ac7
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c a8de1db43335fc4946370a7a7e47d89975ad678ddb15078a150e993ba2fb37d4
F src/json.c e2830f713ac361dbdabcd9017acfb8e8e4a783ff5ca0f3925626edd8c7b11909
F src/json.c dc5befb58a71eca4c3703b2b62f4ef7bfe2087f261a21f84c0aa0f0d930e04f3
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136
F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
@ -2063,8 +2063,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 c13346afbecb92275e741252897d00478dab4be2d158889bc735e80efd9444f5
R 6e312c065e46414b9040d6fd248d4cee
P 85e00c9e68d0695592e8f72555ee133c096bfca5a860a8e21d1e0ef756705aaf
R 2024c2bf9c60e37e973abadb1fa7e9e0
U drh
Z e7a3b5e2b439e9e4434717ea6eca66ea
Z 1a9a05d48349450ebaef68906cd35ee3
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
85e00c9e68d0695592e8f72555ee133c096bfca5a860a8e21d1e0ef756705aaf
58398292e8473b0b9e4b77dd5ed27334bc24a85d0c399e8d0b86de6fb59dadce

View File

@ -1292,7 +1292,7 @@ json_parse_restart:
/* Parse number */
jnFlags = 0;
parse_number:
seenDP = 0;
seenDP = JSON_INT;
seenE = 0;
assert( '-' < '0' );
assert( '+' < '0' );
@ -1304,6 +1304,12 @@ json_parse_restart:
if( sqlite3Isdigit(z[i+1]) ){
pParse->has5 = 1;
jnFlags = JNODE_JSON5;
}else if( (z[i+1]=='x' || z[i+1]=='X') && sqlite3Isxdigit(z[i+2]) ){
assert( seenDP==JSON_INT );
pParse->has5 = 1;
jnFlags |= JNODE_JSON5;
for(j=i+3; sqlite3Isxdigit(z[j]); j++){}
goto parse_number_finish;
}
}else{
if( !sqlite3Isdigit(z[i+1]) ){
@ -1335,20 +1341,27 @@ json_parse_restart:
#endif
return -1;
}
if( z[i+1]=='0' && sqlite3Isdigit(z[i+2]) ){
pParse->has5 = 1;
jnFlags = JNODE_JSON5;
if( z[i+1]=='0' ){
if( sqlite3Isdigit(z[i+2]) ){
pParse->has5 = 1;
jnFlags = JNODE_JSON5;
}else if( (z[i+2]=='x' || z[i+2]=='X') && sqlite3Isxdigit(z[i+3]) ){
pParse->has5 = 1;
jnFlags |= JNODE_JSON5;
for(j=i+4; sqlite3Isxdigit(z[j]); j++){}
goto parse_number_finish;
}
}
}
}
parse_number_2:
for(j=i+1;; j++){
c = z[j];
if( c>='0' && c<='9' ) continue;
if( sqlite3Isdigit(c) ) continue;
if( c=='.' ){
if( z[j-1]=='-' ) return -1;
if( seenDP ) return -1;
seenDP = 1;
if( seenDP==JSON_REAL ) return -1;
seenDP = JSON_REAL;
continue;
}
if( c=='e' || c=='E' ){
@ -1361,7 +1374,8 @@ json_parse_restart:
}
}
if( seenE ) return -1;
seenDP = seenE = 1;
seenDP = JSON_REAL;
seenE = 1;
c = z[j+1];
if( c=='+' || c=='-' ){
j++;
@ -1370,16 +1384,6 @@ json_parse_restart:
if( c<'0' || c>'9' ) return -1;
continue;
}
if( (c=='x' || c=='X')
&& (j==i+1 || (j==i+2 && (z[i]=='-' || z[i]=='+')))
&& z[j-1]=='0'
&& sqlite3Isxdigit(z[j+1])
){
assert( seenDP==0 );
pParse->has5 = 1;
jnFlags |= JNODE_JSON5;
for(j=j+2; sqlite3Isxdigit(z[j]); j++){}
}
break;
}
if( z[j-1]<'0' ){
@ -1390,8 +1394,8 @@ json_parse_restart:
return -1;
}
}
jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
j - i, &z[i]);
parse_number_finish:
jsonParseAddNode(pParse, seenDP, j - i, &z[i]);
if( jnFlags && !pParse->oom ){
pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
}