From: drh <> Date: Wed, 26 Apr 2023 17:30:28 +0000 (+0000) Subject: Partial implementation of JSON5 numeric literal extensions. Use a switch() X-Git-Tag: version-3.42.0~73^2~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f14b2e35fa2bcacdf14a3be31e7370670ebd1e34;p=thirdparty%2Fsqlite.git Partial implementation of JSON5 numeric literal extensions. Use a switch() statement in the parser for better performance. FossilOrigin-Name: 78404dc37024cad5fe7eacf78ea85b56f08b129a1b9a046c3e1b11275068a485 --- diff --git a/manifest b/manifest index 901405d91b..aefd7ea121 100644 --- a/manifest +++ b/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. -D 2023-04-26T15:58:08.228 +C Partial\simplementation\sof\sJSON5\snumeric\sliteral\sextensions.\s\sUse\sa\sswitch()\nstatement\sin\sthe\sparser\sfor\sbetter\sperformance. +D 2023-04-26T17:30:28.870 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 d0f9a0c630bdea3721e28b5ba2fce119c0e732ad48f6674a8f1644f2ec45ffb1 +F src/json.c a346dbe63628f8cb9c6bf6bbccb8fc81a49730db2311ec9b483d7fc3582da223 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136 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-speed-check.sh 8b7babf530faa58bd59d6d362cec8e9036a68c5457ff46f3b1f1511d21af6737 x F test/json101.test de9c93169b84ac96fd5836c638a2ae1f00e4afbd4003c6b596692d7f05e1cd69 -F test/json102.test 327e77275f338c028faefa2da5164daf6b142a165e3015ff2a6e4251ddc6a0ac +F test/json102.test 1f61f469d763ff26430dbee76bc75e0aa73084ca84f10e58744fdb899e56de3e F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe F test/json104.test a502dc01853aada95d721b3b275afbe2dc18fffdac1fea6e96fb20c13586bbb5 F test/json105.test 11670a4387f4308ae0318cadcbd6a918ea7edcd19fbafde020720a073952675d @@ -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 d262c059455ebe0650a45a6c1c04d1baf9609c635df352732dd192426e1bdc39 -R 3eb29750520f57f10b6b50d11e64a15f +P ac411dbdcbf0b9040fb5b7de173271f383a6aa303d57f22ebd200809a5b4a6d3 +R 0e63126100fc0a5fcfa419eb4dbeae91 U drh -Z f254fb62ebf6c065b09ee32328c8e984 +Z 7c56c83a7327e89fcacb5797373de3a9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 288ecccb2f..76ab21e90f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ac411dbdcbf0b9040fb5b7de173271f383a6aa303d57f22ebd200809a5b4a6d3 \ No newline at end of file +78404dc37024cad5fe7eacf78ea85b56f08b129a1b9a046c3e1b11275068a485 \ No newline at end of file diff --git a/src/json.c b/src/json.c index 58f89b1aaa..63feff9488 100644 --- a/src/json.c +++ b/src/json.c @@ -912,10 +912,9 @@ static int jsonParseValue(JsonParse *pParse, u32 i){ int x; JsonNode *pNode; const char *z = pParse->zJson; - while( fast_isspace(z[i]) ){ i++; } json_parse_restart: - c = z[i]; - if( c=='{' ){ + switch( (u8)z[i] ){ + case '{': { /* Parse object */ iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0); if( iThis<0 ) return -1; @@ -951,7 +950,8 @@ json_parse_restart: } pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1; return j+1; - }else if( c=='[' ){ + } + case '[': { /* Parse array */ iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0); if( iThis<0 ) return -1; @@ -977,7 +977,8 @@ json_parse_restart: } pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1; return j+1; - }else if( c=='"' ){ + } + case '"': { /* Parse string */ u8 jnFlags = 0; j = i+1; @@ -1004,32 +1005,61 @@ json_parse_restart: jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]); if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags; return j+1; - }else if( c=='n' - && strncmp(z+i,"null",4)==0 - && !sqlite3Isalnum(z[i+4]) ){ - jsonParseAddNode(pParse, JSON_NULL, 0, 0); - return i+4; - }else if( c=='t' - && strncmp(z+i,"true",4)==0 - && !sqlite3Isalnum(z[i+4]) ){ - jsonParseAddNode(pParse, JSON_TRUE, 0, 0); - return i+4; - }else if( c=='f' - && strncmp(z+i,"false",5)==0 - && !sqlite3Isalnum(z[i+5]) ){ - jsonParseAddNode(pParse, JSON_FALSE, 0, 0); - return i+5; - }else if( c=='-' || (c>='0' && c<='9') ){ + } + case 'n': { + if( strncmp(z+i,"null",4)==0 && !sqlite3Isalnum(z[i+4]) ){ + jsonParseAddNode(pParse, JSON_NULL, 0, 0); + return i+4; + } + return -1; + } + case 't': { + if( strncmp(z+i,"true",4)==0 && !sqlite3Isalnum(z[i+4]) ){ + jsonParseAddNode(pParse, JSON_TRUE, 0, 0); + return i+4; + } + return -1; + } + 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 */ u8 seenDP = 0; u8 seenE = 0; assert( '-' < '0' ); + assert( '+' < '0' ); + assert( '.' < '0' ); + c = z[i]; + if( c<='0' ){ - j = c=='-' ? i+1 : i; - if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1; + if( c=='0' ){ + 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++){ + for(j=i+1;; j++){ c = z[j]; if( c>='0' && c<='9' ) continue; if( c=='.' ){ @@ -1074,19 +1104,44 @@ json_parse_restart: jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT, j - i, &z[i]); return j; - }else if( c=='}' ){ + } + case '}': { return -2; /* End of {...} */ - }else if( c==']' ){ + } + case ']': { return -3; /* End of [...] */ - }else if( c==0 ){ + } + case 0: { return 0; /* End of file */ - }else if( (j = json5Whitespace(&z[i]))>0 ){ - i += j; - pParse->has5 = 1; + } + case 0x09: + case 0x0a: + case 0x0d: + case 0x20: { + do{ + i++; + }while( fast_isspace(z[i]) ); 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 int k, nn; + c = z[i]; for(k=0; k