-C If\sthe\sinput\sJSON\sto\sa\sjson\sfunction\sthat\suses\scache\scomes\sfrom\san\sRCStr\nvalue,\sthen\suse\sthat\sRCStr\svalue\sin\sthe\sparse\srather\sthan\smaking\sa\scopy.
-D 2023-07-27T20:28:29.957
+C Switch\sto\susing\sjsonParseCached()\sfor\sjson_patch().
+D 2023-07-27T23:51:36.392
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
-F src/json.c 481dffa457276d850836953bbd2a61a00a98f8cf09c64c29c6f05ac02a84affd
+F src/json.c 60b6b0815ddaf546396e3c7328065a114b581721dc1fa20697a52610fb2259aa
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 176d6b2cb18a6ad73b133db17f6fc351c4d9a2d510deebdb76c22bde9cfd1465
F src/main.c 512b1d45bc556edf4471a845afb7ba79e64bd5b832ab222dc195c469534cd002
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P ab1edcc7fedcf27922d5db4bc1bc673b1495ca9c66eb6debdda7b7776c068888
-R bc4f27407c20176b7c3faf6538598e39
+P 509ae9c1470dd79d320e84371e1e6662fb85fa0571df5ed8c4d946d10cdfe821
+R a667d9301618252314cdf4d506cbebf3
U drh
-Z 559a7376c279a69632a349e06eee6ec2
+Z 152f86b69395ef2af8d236118a3bf25d
# Remove this line to create a well-formed Fossil manifest.
** are any errors. If an error occurs, free all memory held by pParse,
** but not pParse itself.
**
-** pParse is uninitialized when this routine is called.
-**
-** pParse->nJPRef set to 1. The caller becomes the owner of the
-** the JsonParse object.
-**
-** pParse->bOwnsJson is set to bTakeJson. If bTakeJson is 1, the newly
-** initialized JsonParse object will become the owner of the zJson input
-** string. If bTakeJson is 0, then the caller is responsible for
-** preserving zJson for the lifetime of the JsonParse object.
+** pParse must be initialized to an empty parse object prior to calling
+** this routine.
*/
static int jsonParse(
JsonParse *pParse, /* Initialize and fill this JsonParse object */
- sqlite3_context *pCtx, /* Report errors here */
- char *zJson /* Input JSON text to be parsed */
+ sqlite3_context *pCtx /* Report errors here */
){
int i;
- memset(pParse, 0, sizeof(*pParse));
- if( zJson==0 ) return 1;
- pParse->zJson = zJson;
- pParse->nJPRef = 1;
+ const char *zJson = pParse->zJson;
i = jsonParseValue(pParse, 0);
if( pParse->oom ) i = -1;
if( i>0 ){
u32 iMinHold = 0xffffffff;
u32 iMaxHold = 0;
int bJsonRCStr;
- int rc;
if( zJson==0 ) return 0;
for(iKey=0; iKey<JSON_CACHE_SZ; iKey++){
memset(p, 0, sizeof(*p));
if( bJsonRCStr ){
p->zJson = sqlite3RCStrRef(zJson);
+ p->bJsonIsRCStr = 1;
}else{
p->zJson = (char*)&p[1];
memcpy(p->zJson, zJson, nJson+1);
}
- rc = jsonParse(p, pErrCtx, p->zJson);
- p->bJsonIsRCStr = bJsonRCStr;
- if( rc ){
+ p->nJPRef = 1;
+ if( jsonParse(p, pErrCtx) ){
if( pErrCtx==0 ){
p->nErr = 1;
assert( p->nJPRef==1 ); /* Caller will own the new JsonParse object p */
int argc,
sqlite3_value **argv
){
- JsonParse x; /* The JSON that is being patched */
- JsonParse y; /* The patch */
+ JsonParse *pX; /* The JSON that is being patched */
+ JsonParse *pY; /* The patch */
JsonNode *pResult; /* The result of the merge */
UNUSED_PARAMETER(argc);
- if( jsonParse(&x, ctx, (char*)sqlite3_value_text(argv[0])) ) return;
- if( jsonParse(&y, ctx, (char*)sqlite3_value_text(argv[1])) ){
- jsonParseReset(&x);
- return;
- }
- x.useMod = 1;
- y.useMod = 1;
- pResult = jsonMergePatch(&x, 0, y.aNode);
- assert( pResult!=0 || x.oom );
- if( pResult && x.oom==0 ){
- jsonDebugPrintParse(&x);
+ pX = jsonParseCached(ctx, argv[0], ctx, 1);
+ if( pX==0 ) return;
+ pY = jsonParseCached(ctx, argv[1], ctx, 1);
+ if( pY==0 ) return;
+ pX->useMod = 1;
+ pX->hasMod = 1;
+ pY->useMod = 1;
+ pResult = jsonMergePatch(pX, 0, pY->aNode);
+ assert( pResult!=0 || pX->oom );
+ if( pResult && pX->oom==0 ){
+ jsonDebugPrintParse(pX);
jsonDebugPrintNode(pResult);
- jsonReturnJson(&x, pResult, ctx, 0);
+ jsonReturnJson(pX, pResult, ctx, 0);
}else{
sqlite3_result_error_nomem(ctx);
}
- jsonParseReset(&x);
- jsonParseReset(&y);
}
/* Reset a JsonEachCursor back to its original state. Free any memory
** held. */
static void jsonEachCursorReset(JsonEachCursor *p){
- sqlite3_free(p->zJson);
sqlite3_free(p->zRoot);
jsonParseReset(&p->sParse);
p->iRowid = 0;
if( idxNum==0 ) return SQLITE_OK;
z = (const char*)sqlite3_value_text(argv[0]);
if( z==0 ) return SQLITE_OK;
- n = sqlite3_value_bytes(argv[0]);
- p->zJson = sqlite3_malloc64( n+1 );
- if( p->zJson==0 ) return SQLITE_NOMEM;
- memcpy(p->zJson, z, (size_t)n+1);
- if( jsonParse(&p->sParse, 0, p->zJson) ){
+ memset(&p->sParse, 0, sizeof(p->sParse));
+ p->sParse.nJPRef = 1;
+ if( sqlite3ValueIsOfClass(argv[0], (void(*)(void*))sqlite3RCStrUnref) ){
+ p->sParse.zJson = sqlite3RCStrRef((char*)z);
+ }else{
+ n = sqlite3_value_bytes(argv[0]);
+ p->sParse.zJson = sqlite3RCStrNew( n+1 );
+ if( p->sParse.zJson==0 ) return SQLITE_NOMEM;
+ memcpy(p->sParse.zJson, z, (size_t)n+1);
+ }
+ p->sParse.bJsonIsRCStr = 1;
+ p->zJson = p->sParse.zJson;
+ if( jsonParse(&p->sParse, 0) ){
int rc = SQLITE_NOMEM;
if( p->sParse.oom==0 ){
sqlite3_free(cur->pVtab->zErrMsg);