From: dan Date: Tue, 26 Nov 2013 18:22:59 +0000 (+0000) Subject: Reduce the amount of code used to implement OP_SeekGe and similar. X-Git-Tag: version-3.8.2~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa1776f093a94c46d7d95ae120f0350b2137953b;p=thirdparty%2Fsqlite.git Reduce the amount of code used to implement OP_SeekGe and similar. FossilOrigin-Name: 8b12a15a2a8139d75f56a099f3f6af844da3ac9c --- diff --git a/manifest b/manifest index d7a8adc696..30adfeecf2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spossible\sNULL\spointer\sdeference\sin\sthe\swordcount\stest\sprogram. -D 2013-11-26T16:51:13.426 +C Reduce\sthe\samount\sof\scode\sused\sto\simplement\sOP_SeekGe\sand\ssimilar. +D 2013-11-26T18:22:59.246 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -280,7 +280,7 @@ F src/update.c c05a0ee658f1a149e0960dfd110f3b8bd846bcb0 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c cbe054290f780fcd472b89d701c7404c51ec9684 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 061d30aea5bbe70926236836be259ed217ee65c0 +F src/vdbe.c d9c63f5c5679f6e6c96612264b5674b8020696c4 F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644 F src/vdbeInt.h 05fbda0e061dbc4aaa2709a8cccf3515c245b263 F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed @@ -1143,7 +1143,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P c07caabf2396c84b2ccb0e9f98ae6279ce41c59d -R d1a47818d75d4c09a9dcb48899bdd6d5 -U drh -Z 42f2f4c4e3d27d9172438c5ee2b1524f +P 6f91dca0de908dc2b15130a6593a61c3147a409f +R d3fc734a7145de0774dfe549644c265c +U dan +Z 32a0a7a512d388c26cfa54a9b929b27b diff --git a/manifest.uuid b/manifest.uuid index 50a66e6b11..ffa1d68526 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6f91dca0de908dc2b15130a6593a61c3147a409f \ No newline at end of file +8b12a15a2a8139d75f56a099f3f6af844da3ac9c \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 71e4d673c0..b402a5e6c0 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3510,38 +3510,28 @@ case OP_SeekGt: { /* jump, in3 */ pc = pOp->p2 - 1; break; } - /* If we reach this point, then the P3 value must be a floating - ** point number. */ - assert( (pIn3->flags & MEM_Real)!=0 ); - if( (iKey==SMALLEST_INT64 && pIn3->r<(double)iKey) - || (iKey==LARGEST_INT64 && pIn3->r>(double)iKey) - ){ - /* The P3 value is too large in magnitude to be expressed as an - ** integer. */ - res = 1; - if( pIn3->r<0 ){ - if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt ); - rc = sqlite3BtreeFirst(pC->pCursor, &res); - if( rc!=SQLITE_OK ) goto abort_due_to_error; - } - }else{ - if( oc<=OP_SeekLe ){ assert( oc==OP_SeekLt || oc==OP_SeekLe ); - rc = sqlite3BtreeLast(pC->pCursor, &res); - if( rc!=SQLITE_OK ) goto abort_due_to_error; - } - } - if( res ){ - pc = pOp->p2 - 1; - } - break; - }else if( oc==OP_SeekLt || oc==OP_SeekGe ){ - /* Use the ceiling() function to convert real->int */ - if( pIn3->r > (double)iKey ) iKey++; - }else{ - /* Use the floor() function to convert real->int */ - assert( oc==OP_SeekLe || oc==OP_SeekGt ); - if( pIn3->r < (double)iKey ) iKey--; + /* If the approximation iKey is larger than the actual real search + ** term, substitute >= for > and < for <=. e.g. if the search term + ** is 4.9 and the integer approximation 5: + ** + ** (x > 4.9) -> (x >= 5) + ** (x <= 4.9) -> (x < 5) + */ + if( pIn3->r<(double)iKey ){ + assert( OP_SeekGe==(OP_SeekGt-1) ); + assert( OP_SeekLt==(OP_SeekLe-1) ); + assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); + if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--; + } + + /* If the approximation iKey is smaller than the actual real search + ** term, substitute <= for < and > for >=. */ + else if( pIn3->r>(double)iKey ){ + assert( OP_SeekLe==(OP_SeekLt+1) ); + assert( OP_SeekGt==(OP_SeekGe+1) ); + assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); + if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++; } } rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);