From: drh Date: Mon, 11 Jan 2016 22:58:50 +0000 (+0000) Subject: Performance optimization in the sqlite3VdbeChangeP4() routine of the X-Git-Tag: version-3.11.0~164 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=00dcecab193d4b9c008caa50ccb10f479a5aae96;p=thirdparty%2Fsqlite.git Performance optimization in the sqlite3VdbeChangeP4() routine of the code generator. FossilOrigin-Name: 28bd8d5fc541464b69886b7e886939035b42a869 --- diff --git a/manifest b/manifest index 6a59c023df..41cffbc0d6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sduplicate\stest\snumber\sin\s'waloverwrite'. -D 2016-01-11T22:43:04.382 +C Performance\soptimization\sin\sthe\ssqlite3VdbeChangeP4()\sroutine\sof\sthe\ncode\sgenerator. +D 2016-01-11T22:58:50.164 F Makefile.in 7c8cc4c2f0179efc6fa9492141d1fb65f4807054 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e45d8b9b56dfa3f2cd860b2c28bd9d304513b042 @@ -402,7 +402,7 @@ F src/vdbe.c 6572d00eefeaa0b14b325fdf3a409920ec3fee82 F src/vdbe.h efb7a8c1459e31f3ea4377824c6a7e4cb5068637 F src/vdbeInt.h 42eefa4f9e7432b9968d321b44e48821ec13b189 F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca -F src/vdbeaux.c 5d8c7c04e0f677033efb1292248a5f9056bbc34c +F src/vdbeaux.c f2e6b4fae037db04323be8de7bcd266375746471 F src/vdbeblob.c fdc4a81605ae7a35ae94a55bd768b66d6be16f15 F src/vdbemem.c fdd1578e47bea61390d472de53c565781d81e045 F src/vdbesort.c a7ec02da4494c59dfd071126dd3726be5a11459d @@ -412,7 +412,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 92ca9e7923c337c497e4c9aa7edac800e269a1d8 F src/wal.h 907943dfdef10b583e81906679a347e0ec6f1b1b F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c c6d3d2f6af57d574a7365ee2b225a5024f2a6bec +F src/where.c bb69654f841ae7af0a20cc6fb8f0ac57901c31be F src/whereInt.h 78b6b4de94db84aecbdc07fe3e38f648eb391e9a F src/wherecode.c dfbfe198e418b01f208b489e088edd230c91a4e7 F src/whereexpr.c eebba8340c90de73b3d3bbe8c43b84559b8e6e2c @@ -1407,7 +1407,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P ecc98bef43c2fd07d64e4efddf340929a875ebac -R bffff77db2267e7f44f05491f1b6c72d -U mistachkin -Z 70102cc7ed23bad282b82f2981075253 +P f5fb82686697e5fa1937323b1c1b35cf90ad0302 +R 5cc83036f9c9da1fadf85dd4abd0f133 +U drh +Z a8c9a7d6a102c57d4a0aed7eac3aa290 diff --git a/manifest.uuid b/manifest.uuid index d694eba5b3..aa9453cfcd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f5fb82686697e5fa1937323b1c1b35cf90ad0302 \ No newline at end of file +28bd8d5fc541464b69886b7e886939035b42a869 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index aa8070a132..2f65d85777 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -305,8 +305,7 @@ int sqlite3VdbeAddOp4Dup8( */ void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere){ int j; - int addr = sqlite3VdbeAddOp3(p, OP_ParseSchema, iDb, 0, 0); - sqlite3VdbeChangeP4(p, addr, zWhere, P4_DYNAMIC); + sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC); for(j=0; jdb->nDb; j++) sqlite3VdbeUsesBtree(p, j); } @@ -805,7 +804,7 @@ static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){ if( aOp ){ Op *pOp; for(pOp=aOp; pOp<&aOp[nOp]; pOp++){ - freeP4(db, pOp->p4type, pOp->p4.p); + if( pOp->p4type ) freeP4(db, pOp->p4type, pOp->p4.p); #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS sqlite3DbFree(db, pOp->zComment); #endif @@ -867,16 +866,34 @@ int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){ ** ** If addr<0 then change P4 on the most recently inserted instruction. */ +static void SQLITE_NOINLINE vdbeChangeP4Full( + Vdbe *p, + Op *pOp, + const char *zP4, + int n +){ + if( pOp->p4type ){ + freeP4(p->db, pOp->p4type, pOp->p4.p); + pOp->p4type = 0; + pOp->p4.p = 0; + } + if( n<0 ){ + sqlite3VdbeChangeP4(p, (int)(pOp - p->aOp), zP4, n); + }else{ + if( n==0 ) n = sqlite3Strlen30(zP4); + pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n); + pOp->p4type = P4_DYNAMIC; + } +} void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){ Op *pOp; sqlite3 *db; assert( p!=0 ); db = p->db; assert( p->magic==VDBE_MAGIC_INIT ); - if( p->aOp==0 || db->mallocFailed ){ - if( n!=P4_VTAB ){ - freeP4(db, n, (void*)*(char**)&zP4); - } + assert( p->aOp!=0 || db->mallocFailed ); + if( db->mallocFailed ){ + if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4); return; } assert( p->nOp>0 ); @@ -885,43 +902,20 @@ void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){ addr = p->nOp - 1; } pOp = &p->aOp[addr]; - assert( pOp->p4type==P4_NOTUSED - || pOp->p4type==P4_INT32 - || pOp->p4type==P4_KEYINFO ); - freeP4(db, pOp->p4type, pOp->p4.p); - pOp->p4.p = 0; + if( n>=0 || pOp->p4type ){ + vdbeChangeP4Full(p, pOp, zP4, n); + return; + } if( n==P4_INT32 ){ /* Note: this cast is safe, because the origin data point was an int ** that was cast to a (const char *). */ pOp->p4.i = SQLITE_PTR_TO_INT(zP4); pOp->p4type = P4_INT32; - }else if( zP4==0 ){ - pOp->p4.p = 0; - pOp->p4type = P4_NOTUSED; - }else if( n==P4_KEYINFO ){ - pOp->p4.p = (void*)zP4; - pOp->p4type = P4_KEYINFO; -#ifdef SQLITE_ENABLE_CURSOR_HINTS - }else if( n==P4_EXPR ){ - /* Responsibility for deleting the Expr tree is handed over to the - ** VDBE by this operation. The caller should have already invoked - ** sqlite3ExprDup() or whatever other routine is needed to make a - ** private copy of the tree. */ - pOp->p4.pExpr = (Expr*)zP4; - pOp->p4type = P4_EXPR; -#endif - }else if( n==P4_VTAB ){ - pOp->p4.p = (void*)zP4; - pOp->p4type = P4_VTAB; - sqlite3VtabLock((VTable *)zP4); - assert( ((VTable *)zP4)->db==p->db ); - }else if( n<0 ){ + }else if( zP4!=0 ){ + assert( n<0 ); pOp->p4.p = (void*)zP4; pOp->p4type = (signed char)n; - }else{ - if( n==0 ) n = sqlite3Strlen30(zP4); - pOp->p4.z = sqlite3DbStrNDup(p->db, zP4, n); - pOp->p4type = P4_DYNAMIC; + if( n==P4_VTAB ) sqlite3VtabLock((VTable*)zP4); } } diff --git a/src/where.c b/src/where.c index e86e26ef1a..2cb8334ffb 100644 --- a/src/where.c +++ b/src/where.c @@ -4318,8 +4318,7 @@ WhereInfo *sqlite3WhereBegin( Bitmask b = pTabItem->colUsed; int n = 0; for(; b; b=b>>1, n++){} - sqlite3VdbeChangeP4(v, sqlite3VdbeCurrentAddr(v)-1, - SQLITE_INT_TO_PTR(n), P4_INT32); + sqlite3VdbeChangeP4(v, -1, SQLITE_INT_TO_PTR(n), P4_INT32); assert( n<=pTab->nCol ); } #ifdef SQLITE_ENABLE_CURSOR_HINTS