aboutsummaryrefslogtreecommitdiff
path: root/src/json.c
diff options
context:
space:
mode:
authordrh <>2023-07-19 13:50:31 +0000
committerdrh <>2023-07-19 13:50:31 +0000
commit7a816e771a803d2be135626b7cb6d7506967acc6 (patch)
tree08fb9c1e27351ab9f0a7655ff45b890071cb8467 /src/json.c
parent37fd50df1fdf67ba2d46dab956b921d14ad956be (diff)
downloadsqlite-7a816e771a803d2be135626b7cb6d7506967acc6.tar.gz
sqlite-7a816e771a803d2be135626b7cb6d7506967acc6.zip
Performance optimization for parsing large JSONs that contain lots of text.
FossilOrigin-Name: c9fbe0185cd5d64950724b00cd0bfb3a7939a985040465a0f35f445acb6e94a6
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/json.c b/src/json.c
index 6bad1c1e7..b67da9327 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1235,15 +1235,9 @@ json_parse_restart:
jnFlags = 0;
parse_string:
cDelim = z[i];
- j = i+1;
- for(;;){
- c = z[j];
- if( (c & ~0x1f)==0 ){
- /* Control characters are not allowed in strings */
- pParse->iErr = j;
- return -1;
- }
- if( c=='\\' ){
+ for(j=i+1; 1; j++){
+ unsigned char uc = (unsigned char)z[j];
+ if( uc=='\\' ){
c = z[++j];
if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
|| c=='n' || c=='r' || c=='t'
@@ -1263,10 +1257,15 @@ json_parse_restart:
pParse->iErr = j;
return -1;
}
- }else if( c==cDelim ){
+ }else if( uc>'\'' ){
+ continue;
+ }else if( uc==cDelim ){
break;
+ }else if( uc<=0x1f ){
+ /* Control characters are not allowed in strings */
+ pParse->iErr = j;
+ return -1;
}
- j++;
}
jsonParseAddNode(pParse, JSON_STRING | (jnFlags<<8), j+1-i, &z[i]);
return j+1;