From 5bfa7e65d10aa3fc9ad8c1a8a139ea516f11e4b7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 1 Dec 2023 13:28:13 +0000 Subject: [PATCH] Cache is working better, but does not preserve the hasJson5 flag. FossilOrigin-Name: a12add7ab9f5aee5bb2ede0c4d22e599dd28f7a107dce72b2ea48ef92d233e8a --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/json.c | 32 ++++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 3cac80e1a7..8aa6ceaf3b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C First\sattempt\sto\sget\sthe\sJSON\stext-to-binary\scache\sworking.\s\sAll\stest\scases\npass,\sbut\sthe\scache\sseems\snot\sto\shelp\smuch. -D 2023-12-01T12:57:12.578 +C Cache\sis\sworking\sbetter,\sbut\sdoes\snot\spreserve\sthe\shasJson5\sflag. +D 2023-12-01T13:28:13.897 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -688,7 +688,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c 9a96faf916f572deb94b6cc7673ba6e299c48d153c18218e104a2c6ae37c2c8e +F src/json.c 32e3741e5ff9f8380ebf84dcd6d3c28ddcd7f6a2923b72a05165ad108ca0c278 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 F src/main.c 1b89f3de98d1b59fec5bac1d66d6ece21f703821b8eaa0d53d9604c35309f6f9 @@ -2145,8 +2145,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 11ebb5f712cc7a515e2e0f2be8c1d71de20c97fe5b74c4f4d72c84fd21182d35 -R 18f6bb3dc7a73112aa5c773b9941447e +P 25ed295f300fea6185104a73721076bccd2b2a6e411c78564266fa6dca4ff70c +R b145e990ca1c690b2dc7d50ed4bd4abc +T *branch * jsonb-cache +T *sym-jsonb-cache * +T -sym-jsonb * U drh -Z 9a005b4c0b238db6966807971445cc41 +Z 663fd17309f10179421e079add21165c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 298549f7a8..697f12705c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -25ed295f300fea6185104a73721076bccd2b2a6e411c78564266fa6dca4ff70c \ No newline at end of file +a12add7ab9f5aee5bb2ede0c4d22e599dd28f7a107dce72b2ea48ef92d233e8a \ No newline at end of file diff --git a/src/json.c b/src/json.c index 44fa5bf0b2..5f02a1c8ed 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: