mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Partial implementation of JSON5 numeric literal extensions. Use a switch()
statement in the parser for better performance. FossilOrigin-Name: 78404dc37024cad5fe7eacf78ea85b56f08b129a1b9a046c3e1b11275068a485
This commit is contained in:
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
|||||||
C Improvement\sto\sthe\sway\sthe\sJSON\sperformance\smeasure\sscripts\swork\s→\skeep\sthe\ntest\sdatabase\sin\sthe\sdirectory\sof\sthe\stest,\snot\sin\sthe\ssource\stree.
|
C Partial\simplementation\sof\sJSON5\snumeric\sliteral\sextensions.\s\sUse\sa\sswitch()\nstatement\sin\sthe\sparser\sfor\sbetter\sperformance.
|
||||||
D 2023-04-26T15:58:08.228
|
D 2023-04-26T17:30:28.870
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||||
@ -592,7 +592,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
|
|||||||
F src/hwtime.h b638809e083b601b618df877b2e89cb87c2a47a01f4def10be4c4ebb54664ac7
|
F src/hwtime.h b638809e083b601b618df877b2e89cb87c2a47a01f4def10be4c4ebb54664ac7
|
||||||
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
|
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
|
||||||
F src/insert.c a8de1db43335fc4946370a7a7e47d89975ad678ddb15078a150e993ba2fb37d4
|
F src/insert.c a8de1db43335fc4946370a7a7e47d89975ad678ddb15078a150e993ba2fb37d4
|
||||||
F src/json.c d0f9a0c630bdea3721e28b5ba2fce119c0e732ad48f6674a8f1644f2ec45ffb1
|
F src/json.c a346dbe63628f8cb9c6bf6bbccb8fc81a49730db2311ec9b483d7fc3582da223
|
||||||
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
||||||
F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136
|
F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136
|
||||||
F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
|
F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
|
||||||
@ -1254,7 +1254,7 @@ F test/json/json-generator.tcl 229bd293f1865f787c160886cadd282631721925cca2947aa
|
|||||||
F test/json/json-q1.txt 335a7c8ab291d354f33b7decc9559e99a2823d4142291c4be7aa339a631f3c2d
|
F test/json/json-q1.txt 335a7c8ab291d354f33b7decc9559e99a2823d4142291c4be7aa339a631f3c2d
|
||||||
F test/json/json-speed-check.sh 8b7babf530faa58bd59d6d362cec8e9036a68c5457ff46f3b1f1511d21af6737 x
|
F test/json/json-speed-check.sh 8b7babf530faa58bd59d6d362cec8e9036a68c5457ff46f3b1f1511d21af6737 x
|
||||||
F test/json101.test de9c93169b84ac96fd5836c638a2ae1f00e4afbd4003c6b596692d7f05e1cd69
|
F test/json101.test de9c93169b84ac96fd5836c638a2ae1f00e4afbd4003c6b596692d7f05e1cd69
|
||||||
F test/json102.test 327e77275f338c028faefa2da5164daf6b142a165e3015ff2a6e4251ddc6a0ac
|
F test/json102.test 1f61f469d763ff26430dbee76bc75e0aa73084ca84f10e58744fdb899e56de3e
|
||||||
F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe
|
F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe
|
||||||
F test/json104.test a502dc01853aada95d721b3b275afbe2dc18fffdac1fea6e96fb20c13586bbb5
|
F test/json104.test a502dc01853aada95d721b3b275afbe2dc18fffdac1fea6e96fb20c13586bbb5
|
||||||
F test/json105.test 11670a4387f4308ae0318cadcbd6a918ea7edcd19fbafde020720a073952675d
|
F test/json105.test 11670a4387f4308ae0318cadcbd6a918ea7edcd19fbafde020720a073952675d
|
||||||
@ -2063,8 +2063,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P d262c059455ebe0650a45a6c1c04d1baf9609c635df352732dd192426e1bdc39
|
P ac411dbdcbf0b9040fb5b7de173271f383a6aa303d57f22ebd200809a5b4a6d3
|
||||||
R 3eb29750520f57f10b6b50d11e64a15f
|
R 0e63126100fc0a5fcfa419eb4dbeae91
|
||||||
U drh
|
U drh
|
||||||
Z f254fb62ebf6c065b09ee32328c8e984
|
Z 7c56c83a7327e89fcacb5797373de3a9
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
@ -1 +1 @@
|
|||||||
ac411dbdcbf0b9040fb5b7de173271f383a6aa303d57f22ebd200809a5b4a6d3
|
78404dc37024cad5fe7eacf78ea85b56f08b129a1b9a046c3e1b11275068a485
|
120
src/json.c
120
src/json.c
@ -912,10 +912,9 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
|||||||
int x;
|
int x;
|
||||||
JsonNode *pNode;
|
JsonNode *pNode;
|
||||||
const char *z = pParse->zJson;
|
const char *z = pParse->zJson;
|
||||||
while( fast_isspace(z[i]) ){ i++; }
|
|
||||||
json_parse_restart:
|
json_parse_restart:
|
||||||
c = z[i];
|
switch( (u8)z[i] ){
|
||||||
if( c=='{' ){
|
case '{': {
|
||||||
/* Parse object */
|
/* Parse object */
|
||||||
iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
|
iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
|
||||||
if( iThis<0 ) return -1;
|
if( iThis<0 ) return -1;
|
||||||
@ -951,7 +950,8 @@ json_parse_restart:
|
|||||||
}
|
}
|
||||||
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
|
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
|
||||||
return j+1;
|
return j+1;
|
||||||
}else if( c=='[' ){
|
}
|
||||||
|
case '[': {
|
||||||
/* Parse array */
|
/* Parse array */
|
||||||
iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
|
iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
|
||||||
if( iThis<0 ) return -1;
|
if( iThis<0 ) return -1;
|
||||||
@ -977,7 +977,8 @@ json_parse_restart:
|
|||||||
}
|
}
|
||||||
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
|
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
|
||||||
return j+1;
|
return j+1;
|
||||||
}else if( c=='"' ){
|
}
|
||||||
|
case '"': {
|
||||||
/* Parse string */
|
/* Parse string */
|
||||||
u8 jnFlags = 0;
|
u8 jnFlags = 0;
|
||||||
j = i+1;
|
j = i+1;
|
||||||
@ -1004,32 +1005,61 @@ json_parse_restart:
|
|||||||
jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
|
jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
|
||||||
if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
|
if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
|
||||||
return j+1;
|
return j+1;
|
||||||
}else if( c=='n'
|
}
|
||||||
&& strncmp(z+i,"null",4)==0
|
case 'n': {
|
||||||
&& !sqlite3Isalnum(z[i+4]) ){
|
if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){
|
||||||
jsonParseAddNode(pParse, JSON_NULL, 0, 0);
|
jsonParseAddNode(pParse, JSON_NULL, 0, 0);
|
||||||
return i+4;
|
return i+4;
|
||||||
}else if( c=='t'
|
}
|
||||||
&& strncmp(z+i,"true",4)==0
|
return -1;
|
||||||
&& !sqlite3Isalnum(z[i+4]) ){
|
}
|
||||||
jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
|
case 't': {
|
||||||
return i+4;
|
if( strncmp(z+i,"true",4)==0 && !sqlite3Isalnum(z[i+4]) ){
|
||||||
}else if( c=='f'
|
jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
|
||||||
&& strncmp(z+i,"false",5)==0
|
return i+4;
|
||||||
&& !sqlite3Isalnum(z[i+5]) ){
|
}
|
||||||
jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
|
return -1;
|
||||||
return i+5;
|
}
|
||||||
}else if( c=='-' || (c>='0' && c<='9') ){
|
case 'f': {
|
||||||
|
if( strncmp(z+i,"false",5)==0 && !sqlite3Isalnum(z[i+5]) ){
|
||||||
|
jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
|
||||||
|
return i+5;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
case '+':
|
||||||
|
pParse->has5 = 1;
|
||||||
|
/* fall through */
|
||||||
|
case '-':
|
||||||
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9': {
|
||||||
/* Parse number */
|
/* Parse number */
|
||||||
u8 seenDP = 0;
|
u8 seenDP = 0;
|
||||||
u8 seenE = 0;
|
u8 seenE = 0;
|
||||||
assert( '-' < '0' );
|
assert( '-' < '0' );
|
||||||
|
assert( '+' < '0' );
|
||||||
|
assert( '.' < '0' );
|
||||||
|
c = z[i];
|
||||||
|
|
||||||
if( c<='0' ){
|
if( c<='0' ){
|
||||||
j = c=='-' ? i+1 : i;
|
if( c=='0' ){
|
||||||
if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
|
if( sqlite3Isdigit(z[i+1]) ){
|
||||||
|
pParse->has5 = 1;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if( !sqlite3Isdigit(z[i+1]) ) return -1;
|
||||||
|
if( z[i+1]=='0' && sqlite3Isdigit(z[i+2]) ) pParse->has5 = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
j = i+1;
|
for(j=i+1;; j++){
|
||||||
for(;; j++){
|
|
||||||
c = z[j];
|
c = z[j];
|
||||||
if( c>='0' && c<='9' ) continue;
|
if( c>='0' && c<='9' ) continue;
|
||||||
if( c=='.' ){
|
if( c=='.' ){
|
||||||
@ -1074,19 +1104,44 @@ json_parse_restart:
|
|||||||
jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
|
jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
|
||||||
j - i, &z[i]);
|
j - i, &z[i]);
|
||||||
return j;
|
return j;
|
||||||
}else if( c=='}' ){
|
}
|
||||||
|
case '}': {
|
||||||
return -2; /* End of {...} */
|
return -2; /* End of {...} */
|
||||||
}else if( c==']' ){
|
}
|
||||||
|
case ']': {
|
||||||
return -3; /* End of [...] */
|
return -3; /* End of [...] */
|
||||||
}else if( c==0 ){
|
}
|
||||||
|
case 0: {
|
||||||
return 0; /* End of file */
|
return 0; /* End of file */
|
||||||
}else if( (j = json5Whitespace(&z[i]))>0 ){
|
}
|
||||||
i += j;
|
case 0x09:
|
||||||
pParse->has5 = 1;
|
case 0x0a:
|
||||||
|
case 0x0d:
|
||||||
|
case 0x20: {
|
||||||
|
do{
|
||||||
|
i++;
|
||||||
|
}while( fast_isspace(z[i]) );
|
||||||
goto json_parse_restart;
|
goto json_parse_restart;
|
||||||
}else{
|
}
|
||||||
|
case 0x0b:
|
||||||
|
case 0x0c:
|
||||||
|
case '/':
|
||||||
|
case 0xc2:
|
||||||
|
case 0xe1:
|
||||||
|
case 0xe2:
|
||||||
|
case 0xe3: {
|
||||||
|
j = json5Whitespace(&z[i]);
|
||||||
|
if( j>0 ){
|
||||||
|
i += j;
|
||||||
|
pParse->has5 = 1;
|
||||||
|
goto json_parse_restart;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
#ifdef SQLITE_ENABLE_JSON_NAN_INF
|
#ifdef SQLITE_ENABLE_JSON_NAN_INF
|
||||||
int k, nn;
|
int k, nn;
|
||||||
|
c = z[i];
|
||||||
for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
|
for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){
|
||||||
if( c!=aNanInfName[k].c1 && c!=aNanInfName[k].c2 ) continue;
|
if( c!=aNanInfName[k].c1 && c!=aNanInfName[k].c2 ) continue;
|
||||||
nn = aNanInfName[k].n;
|
nn = aNanInfName[k].n;
|
||||||
@ -1101,6 +1156,7 @@ json_parse_restart:
|
|||||||
#endif
|
#endif
|
||||||
return -1; /* Syntax error */
|
return -1; /* Syntax error */
|
||||||
}
|
}
|
||||||
|
} /* End switch(z[i]) */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -301,18 +301,27 @@ for {set i 0} {$i<100} {incr i} {
|
|||||||
# allowing them. The following tests verify that the problem is now
|
# allowing them. The following tests verify that the problem is now
|
||||||
# fixed.
|
# fixed.
|
||||||
#
|
#
|
||||||
do_execsql_test json102-1401 { SELECT json_valid('{"x":01}') } 0
|
foreach {id j x0 x5} {
|
||||||
do_execsql_test json102-1402 { SELECT json_valid('{"x":-01}') } 0
|
1401 {'{"x":01}'} 0 1
|
||||||
do_execsql_test json102-1403 { SELECT json_valid('{"x":0}') } 1
|
1402 {'{"x":-01}'} 0 1
|
||||||
do_execsql_test json102-1404 { SELECT json_valid('{"x":-0}') } 1
|
1403 {'{"x":0}'} 1 1
|
||||||
do_execsql_test json102-1405 { SELECT json_valid('{"x":0.1}') } 1
|
1404 {'{"x":-0}'} 1 1
|
||||||
do_execsql_test json102-1406 { SELECT json_valid('{"x":-0.1}') } 1
|
1405 {'{"x":0.1}'} 1 1
|
||||||
do_execsql_test json102-1407 { SELECT json_valid('{"x":0.0000}') } 1
|
1406 {'{"x":-0.1}'} 1 1
|
||||||
do_execsql_test json102-1408 { SELECT json_valid('{"x":-0.0000}') } 1
|
1407 {'{"x":0.0000}'} 1 1
|
||||||
do_execsql_test json102-1409 { SELECT json_valid('{"x":01.5}') } 0
|
1408 {'{"x":-0.0000}'} 1 1
|
||||||
do_execsql_test json102-1410 { SELECT json_valid('{"x":-01.5}') } 0
|
1409 {'{"x":01.5}'} 0 1
|
||||||
do_execsql_test json102-1411 { SELECT json_valid('{"x":00}') } 0
|
1410 {'{"x":-01.5}'} 0 1
|
||||||
do_execsql_test json102-1412 { SELECT json_valid('{"x":-00}') } 0
|
1411 {'{"x":00}'} 0 1
|
||||||
|
1412 {'{"x":-00}'} 0 1
|
||||||
|
1413 {'{"x":+0}'} 0 1
|
||||||
|
1414 {'{"x":+5}'} 0 1
|
||||||
|
1415 {'{"x":+5.5}'} 0 1
|
||||||
|
} {
|
||||||
|
do_execsql_test json102-$id "
|
||||||
|
SELECT json_valid($j), json_valid5($j);
|
||||||
|
" [list $x0 $x5]
|
||||||
|
}
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
# 2017-04-10 ticket 6c9b5514077fed34551f98e64c09a10dc2fc8e16
|
# 2017-04-10 ticket 6c9b5514077fed34551f98e64c09a10dc2fc8e16
|
||||||
|
Reference in New Issue
Block a user