1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

Performance improvement by unwinding a loop in jsonAppendString().

FossilOrigin-Name: 190ab3c08431a0ba24d76392eab251f5c1792add05e4ec780998b299208eca95
This commit is contained in:
drh
2023-12-28 19:18:08 +00:00
parent 42203e1b75
commit 4c13d3ca92
3 changed files with 34 additions and 9 deletions

View File

@@ -627,8 +627,33 @@ static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
p->zBuf[p->nUsed++] = '"';
while( 1 /*exit-by-break*/ ){
k = 0;
while( k+1<N && jsonIsOk[z[k]] && jsonIsOk[z[k+1]] ){ k += 2; } /* <--, */
while( k<N && jsonIsOk[z[k]] ){ k++; } /* <-- loop unwound for speed */
/* The following while() is the 4-way unwound equivalent of
**
** while( k<N && jsonIsOk[z[k]] ){ k++; }
*/
while( 1 /* Exit by break */ ){
if( k+3>=N ){
while( k<N && jsonIsOk[z[k]] ){ k++; }
break;
}
if( !jsonIsOk[z[k]] ){
break;
}
if( !jsonIsOk[z[k+1]] ){
k += 1;
break;
}
if( !jsonIsOk[z[k+2]] ){
k += 2;
break;
}
if( !jsonIsOk[z[k+3]] ){
k += 3;
break;
}else{
k += 4;
}
}
if( k>=N ){
if( k>0 ){
memcpy(&p->zBuf[p->nUsed], z, k);