diff options
author | drh <drh@noemail.net> | 2016-09-20 01:19:18 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2016-09-20 01:19:18 +0000 |
commit | 8aaf7bcc8d7cbd03d66f34202f6f25a9c19bf8be (patch) | |
tree | f2b4d5bf0c40943a02cbd3b5396b3e1859a323ce /src | |
parent | fadd2b197216f5a708029f709db4751db48b8212 (diff) | |
download | sqlite-8aaf7bcc8d7cbd03d66f34202f6f25a9c19bf8be.tar.gz sqlite-8aaf7bcc8d7cbd03d66f34202f6f25a9c19bf8be.zip |
Avoid unnecessary calls to ExpandBlob() for smaller and faster code.
FossilOrigin-Name: 5e196fd18169e84806cd45dd1a8190339323e772
Diffstat (limited to 'src')
-rw-r--r-- | src/vdbe.c | 7 | ||||
-rw-r--r-- | src/vdbeaux.c | 19 | ||||
-rw-r--r-- | src/vdbemem.c | 18 |
3 files changed, 26 insertions, 18 deletions
diff --git a/src/vdbe.c b/src/vdbe.c index 13c20c462..0cd0147f5 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -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( diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 838a8f044..43f235c7b 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -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); diff --git a/src/vdbemem.c b/src/vdbemem.c index ca6e480d1..efc4a9722 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -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 |