aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2023-12-01 13:28:13 +0000
committerdrh <>2023-12-01 13:28:13 +0000
commit5bfa7e65d10aa3fc9ad8c1a8a139ea516f11e4b7 (patch)
tree010ddd0f51e747c2fa0fc0d41d8749675fdb5e95 /src
parentca1ce7773c42cb128b424c77755f4413663bd81c (diff)
downloadsqlite-5bfa7e65d10aa3fc9ad8c1a8a139ea516f11e4b7.tar.gz
sqlite-5bfa7e65d10aa3fc9ad8c1a8a139ea516f11e4b7.zip
Cache is working better, but does not preserve the hasJson5 flag.
FossilOrigin-Name: a12add7ab9f5aee5bb2ede0c4d22e599dd28f7a107dce72b2ea48ef92d233e8a
Diffstat (limited to 'src')
-rw-r--r--src/json.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/json.c b/src/json.c
index 44fa5bf0b..5f02a1c8e 100644
--- a/src/json.c
+++ b/src/json.c
@@ -358,13 +358,15 @@ static void jsonCacheDeleteGeneric(void *p){
*/
static int jsonCacheInsert(
sqlite3_context *ctx, /* The SQL statement context holding the cache */
- char *zJson, /* The key. Must be an RCStr! */
+ char *zJson, /* The key. */
u32 nJson, /* Number of bytes in zJson */
- char *aBlob, /* The value. Not an RCStr */
+ int bJsonIsRCStr, /* True if zJson is already an RCStr */
+ u8 *aBlob, /* The value. */
u32 nBlob /* Number of bytes in aBlob */
){
JsonCache *p;
- char *aRCBlob = 0;
+ char *aRCBlob;
+ char *zRCJson;
p = sqlite3_get_auxdata(ctx, JSON_CACHE_ID);
if( p==0 ){
@@ -379,6 +381,17 @@ static int jsonCacheInsert(
aRCBlob = sqlite3RCStrNew( nBlob );
if( aRCBlob==0 ) return SQLITE_NOMEM;
memcpy(aRCBlob, aBlob, nBlob);
+ if( bJsonIsRCStr ){
+ zRCJson = sqlite3RCStrRef(zJson);
+ }else{
+ zRCJson = sqlite3RCStrNew( nJson );
+ if( zRCJson==0 ){
+ sqlite3RCStrUnref(aRCBlob);
+ return SQLITE_NOMEM;
+ }
+ memcpy(zRCJson, zJson, nJson);
+ zRCJson[nJson] = 0;
+ }
if( p->nUsed >= JSON_CACHE_SIZE ){
sqlite3RCStrUnref(p->a[0].zJson);
sqlite3RCStrUnref(p->a[0].aBlob);
@@ -387,7 +400,7 @@ static int jsonCacheInsert(
}
p->a[p->nUsed].nJson = nJson;
p->a[p->nUsed].nBlob = nBlob;
- p->a[p->nUsed].zJson = sqlite3RCStrRef(zJson);
+ p->a[p->nUsed].zJson = zRCJson;
p->a[p->nUsed].aBlob = aRCBlob;
p->nUsed++;
return SQLITE_OK;
@@ -429,6 +442,7 @@ static u8 *jsonCacheSearch(
JsonCacheLine tmp = p->a[i];
memmove(&p->a[i], &p->a[i+1], (p->nUsed-i-1)*sizeof(tmp));
p->a[p->nUsed-1] = tmp;
+ i = p->nUsed - 1;
}
*pnBlob = p->a[i].nBlob;
return (u8*)p->a[i].aBlob;
@@ -724,8 +738,8 @@ static void jsonReturnString(
}else if( jsonForceRCStr(p) ){
sqlite3RCStrRef(p->zBuf);
if( pParse ){
- int rc = jsonCacheInsert(ctx, p->zBuf, p->nUsed,
- (char*)pParse->aBlob, pParse->nBlob);
+ int rc = jsonCacheInsert(ctx, p->zBuf, p->nUsed, 1,
+ pParse->aBlob, pParse->nBlob);
if( rc==SQLITE_NOMEM ){
sqlite3RCStrUnref(p->zBuf);
sqlite3_result_error_nomem(ctx);
@@ -2746,6 +2760,12 @@ static JsonParse *jsonParseFuncArg(
return 0;
}
}
+ if( ctx ){
+ int isRCStr = sqlite3ValueIsOfClass(pArg, sqlite3RCStrUnref);
+ int rc = jsonCacheInsert(ctx, p->zJson, p->nJson, isRCStr,
+ p->aBlob, p->nBlob);
+ if( rc==SQLITE_NOMEM ) goto json_pfa_oom;
+ }
return p;
json_pfa_malformed: