Avoid unnecessary calls to ExpandBlob() for smaller and faster code.

FossilOrigin-Name: 5e196fd18169e84806cd45dd1a8190339323e772
This commit is contained in:
drh 2016-09-20 01:19:18 +00:00
parent fadd2b1972
commit 8aaf7bcc8d
5 changed files with 35 additions and 27 deletions

View File

@ -1,5 +1,5 @@
C Very\ssmall\soptimization\sin\sthe\sbytecode\sengine.
D 2016-09-19T23:39:34.157
C Avoid\sunnecessary\scalls\sto\sExpandBlob()\sfor\ssmaller\sand\sfaster\scode.
D 2016-09-20T01:19:18.064
F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc e1aa788e84f926e42239ee167c53f785bedacacd
@ -453,13 +453,13 @@ F src/update.c 8179e699dbd45b92934fd02d3d8e3732e8da8802
F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c
F src/util.c 810ec3f22e2d1b62e66c30fe3621ebdedd23584d
F src/vacuum.c 913970b9d86dd6c2b8063ef1af421880f1464ec3
F src/vdbe.c c21ff59ffcd6e3e208d1e9525f58ae1fc373c8f4
F src/vdbe.c 373b186a945cb69acfd6b3f53d43a3e72120ac8f
F src/vdbe.h c044be7050ac6bf596eecc6ab159f5dbc020a3b7
F src/vdbeInt.h d21f14721dd87975dc9e3bcdbf504f9c098cf611
F src/vdbeapi.c a32d61b7dd05e6890d8fd44d2805f55e2f5ba9f3
F src/vdbeaux.c 66054df369ca76530b6b84e6fce2f847dc99a9b1
F src/vdbeaux.c b9772e4134a17f5b42d32761f5119467815c2458
F src/vdbeblob.c 3e82a797b60c3b9fed7b8de8c539ca7607874937
F src/vdbemem.c 357caac1a404f37ee6087b17613f92107c13f733
F src/vdbemem.c 813e7847fdbf165ab3fcb5ff4f6f04a0b0cca166
F src/vdbesort.c 91fda3909326860382b0ca8aa251e609c6a9d62c
F src/vdbetrace.c 41963d5376f0349842b5fc4aaaaacd7d9cdc0834
F src/vtab.c e02cacb5c7ae742631edeb9ae9f53d399f093fd8
@ -1525,7 +1525,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 2401ea5acfeee8042489d1db38036ff86e8a6916
R 683f7035193075e0587f69a387a06ae5
P 46002511e52518bae14f210157f231c814c77c9e
R 571b30401865528a2fb45b091bacd258
U drh
Z 09002a4c4dfbbe09b9e7daa54e91e112
Z a7955a17fb1911f183df0a2e3aedb1bf

View File

@ -1 +1 @@
46002511e52518bae14f210157f231c814c77c9e
5e196fd18169e84806cd45dd1a8190339323e772

View File

@ -3872,7 +3872,6 @@ case OP_SeekGT: { /* jump, in3 */
#ifdef SQLITE_DEBUG
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
#endif
(void)ExpandBlob(r.aMem);
r.eqSeen = 0;
rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, &r, 0, 0, &res);
if( rc!=SQLITE_OK ){
@ -4013,13 +4012,13 @@ case OP_Found: { /* jump, in3 */
r.pKeyInfo = pC->pKeyInfo;
r.nField = (u16)pOp->p4.i;
r.aMem = pIn3;
#ifdef SQLITE_DEBUG
for(ii=0; ii<r.nField; ii++){
assert( memIsValid(&r.aMem[ii]) );
(void)ExpandBlob(&r.aMem[ii]);
#ifdef SQLITE_DEBUG
assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
#endif
}
#endif
pIdxKey = &r;
}else{
pIdxKey = sqlite3VdbeAllocUnpackedRecord(

View File

@ -3712,10 +3712,12 @@ static int vdbeCompareMemString(
** The input pBlob is guaranteed to be a Blob that is not marked
** with MEM_Zero. Return true if it could be a zero-blob.
*/
static int isZeroBlob(const Mem *pBlob){
static int isAllZero(const char *z, int n){
int i;
for(i=0; i<pBlob->n && pBlob->z[i]==0; i++){}
return i==pBlob->n;
for(i=0; i<n; i++){
if( z[i] ) return 0;
}
return 1;
}
/*
@ -3739,10 +3741,10 @@ static SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){
if( pB1->flags & pB2->flags & MEM_Zero ){
return pB1->u.nZero - pB2->u.nZero;
}else if( pB1->flags & MEM_Zero ){
if( !isZeroBlob(pB2) ) return -1;
if( !isAllZero(pB2->z, pB2->n) ) return -1;
return pB1->u.nZero - n2;
}else{
if( !isZeroBlob(pB1) ) return +1;
if( !isAllZero(pB1->z, pB1->n) ) return +1;
return n1 - pB2->u.nZero;
}
}
@ -4054,6 +4056,7 @@ int sqlite3VdbeRecordCompareWithSkip(
/* RHS is a blob */
else if( pRhs->flags & MEM_Blob ){
assert( (pRhs->flags & MEM_Zero)==0 || pRhs->n==0 );
getVarint32(&aKey1[idx1], serial_type);
testcase( serial_type==12 );
if( serial_type<12 || (serial_type & 0x01) ){
@ -4065,6 +4068,12 @@ int sqlite3VdbeRecordCompareWithSkip(
if( (d1+nStr) > (unsigned)nKey1 ){
pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
return 0; /* Corruption */
}else if( pRhs->flags & MEM_Zero ){
if( !isAllZero((const char*)&aKey1[d1],nStr) ){
rc = 1;
}else{
rc = nStr - pRhs->u.nZero;
}
}else{
int nCmp = MIN(nStr, pRhs->n);
rc = memcmp(&aKey1[d1], pRhs->z, nCmp);

View File

@ -189,18 +189,18 @@ int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
*/
int sqlite3VdbeMemMakeWriteable(Mem *pMem){
int f;
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
assert( (pMem->flags&MEM_RowSet)==0 );
(void)ExpandBlob(pMem);
f = pMem->flags;
if( (f&(MEM_Str|MEM_Blob)) && (pMem->szMalloc==0 || pMem->z!=pMem->zMalloc) ){
if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
return SQLITE_NOMEM_BKPT;
if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){
if( ExpandBlob(pMem) ) return SQLITE_NOMEM;
if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){
if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
return SQLITE_NOMEM_BKPT;
}
pMem->z[pMem->n] = 0;
pMem->z[pMem->n+1] = 0;
pMem->flags |= MEM_Term;
}
pMem->z[pMem->n] = 0;
pMem->z[pMem->n+1] = 0;
pMem->flags |= MEM_Term;
}
pMem->flags &= ~MEM_Ephem;
#ifdef SQLITE_DEBUG