From: drh <> Date: Tue, 3 Oct 2023 20:01:20 +0000 (+0000) Subject: Augment the jsonBlobChangePayloadSize() routine so that it tries to shift X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fjsonb-opt1;p=thirdparty%2Fsqlite.git Augment the jsonBlobChangePayloadSize() routine so that it tries to shift content in order to render the payload size in its minimal form. FossilOrigin-Name: 562e8e7b08c696edee3ad1919df1499ba35eef3cd800667d2eaad749efa28748 --- diff --git a/manifest b/manifest index 40a49f1c48..2d9981fe93 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\shandling\sof\sOOM\swhile\stranslating\sthe\sJsonNode\srepresenting\sinto\nthe\sBLOB\srepresentation. -D 2023-10-03T19:37:19.514 +C Augment\sthe\sjsonBlobChangePayloadSize()\sroutine\sso\sthat\sit\stries\sto\sshift\ncontent\sin\sorder\sto\srender\sthe\spayload\ssize\sin\sits\sminimal\sform. +D 2023-10-03T20:01:20.899 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -670,7 +670,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 6a6437fce0eb558b05fc30c1d806ee342e99ccb2dcae1f53b038c60572f84383 +F src/json.c 0be3a2d1d67a7032bc5f2e3487153974d47011baa4002c33164223102c2d9db5 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40 @@ -2123,8 +2123,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 e6406a9865b75dea2f26d3ee4f4c206958400059c7f92ced88edc8507dd3c82f -R a18f64bf40d3960df89ef1dde4bf90eb +P ef5956710bb542d6045c82937d02218a7ed45af94cf3959b0c180268e04d14e1 +R 2f679d513b89eae674f09a3b39a9f65f +T *branch * jsonb-opt1 +T *sym-jsonb-opt1 * +T -sym-jsonb * U drh -Z d1b86d452a43e36a5aedf44b0fbb363f +Z 0222ad659b75b7c516554e7b4e2a89a4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bea2bfc71f..a69b0daf00 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ef5956710bb542d6045c82937d02218a7ed45af94cf3959b0c180268e04d14e1 \ No newline at end of file +562e8e7b08c696edee3ad1919df1499ba35eef3cd800667d2eaad749efa28748 \ No newline at end of file diff --git a/src/json.c b/src/json.c index c4d874309f..2c03deee0d 100644 --- a/src/json.c +++ b/src/json.c @@ -2608,21 +2608,63 @@ static void jsonBlobChangePayloadSize( if( pParse->oom ) return; a = &pParse->aBlob[i]; szType = a[0]>>4; +restart: if( szType<=11 ){ assert( szPayload<=11 ); a[0] = (a[0] & 0x0f) | (szPayload<<4); }else if( szType==0xc ){ assert( szPayload<=0xff ); assert( i+1nBlob ); - a[1] = szPayload & 0xff; + if( szPayload<=11 ){ + if( i+2nBlob ){ + memmove(&a[1], &a[2], pParse->nBlob - (i+2)); + } + pParse->nBlob--; + a[0] = (a[0] & 0x0f) | (szPayload<<4); + }else{ + a[1] = szPayload & 0xff; + } }else if( szType==0xd ){ assert( szPayload<=0xffff ); assert( i+2nBlob ); + if( szPayload<=0xff ){ + u8 d; + if( szPayload<=11 ){ + d = 2; + szType = szPayload; + }else{ + d = 1; + szType = 0x0c; + } + if( i+3nBlob ){ + memmove(&a[3-d], &a[3], pParse->nBlob - (i+3)); + } + pParse->nBlob -= d; + goto restart; + } a[1] = (szPayload >> 8) & 0xff; a[2] = szPayload & 0xff; }else{ assert( szType==0xe ); assert( i+4nBlob ); + if( szPayload<=0xffff ){ + u8 d; + if( szPayload<=11 ){ + d = 4; + szType = szPayload; + }else if( szPayload<=255 ){ + d = 3; + szType = 0x0c; + }else{ + d = 2; + szType = 0x0d; + } + if( i+5nBlob ){ + memmove(&a[5-d], &a[5], pParse->nBlob - (i+5)); + } + pParse->nBlob -= d; + goto restart; + } a[1] = (szPayload >> 24) & 0xff; a[2] = (szPayload >> 16) & 0xff; a[3] = (szPayload >> 8) & 0xff;