Performance improvements to the comparison operators in the bytecode engine.

FossilOrigin-Name: 37803b19d219f4107f29b240d5d314600e4bd236
This commit is contained in:
drh
2016-09-09 19:33:00 +00:00
parent b80dbdc2f7
commit 64caee4086
4 changed files with 53 additions and 18 deletions
+34 -2
View File
@@ -3716,15 +3716,47 @@ 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){
int i;
for(i=0; i<pBlob->n && pBlob->z[i]==0; i++){}
return i==pBlob->n;
}
/*
** Compare two blobs. Return negative, zero, or positive if the first
** is less than, equal to, or greater than the second, respectively.
** If one blob is a prefix of the other, then the shorter is the lessor.
*/
static SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){
int c = memcmp(pB1->z, pB2->z, pB1->n>pB2->n ? pB2->n : pB1->n);
int c;
int n1 = pB1->n;
int n2 = pB2->n;
/* It is possible to have a Blob value that has some non-zero content
** followed by zero content. But that only comes up for Blobs formed
** by the OP_MakeRecord opcode, and such Blobs never get passed into
** sqlite3MemCompare(). */
assert( (pB1->flags & MEM_Zero)==0 || n1==0 );
assert( (pB2->flags & MEM_Zero)==0 || n2==0 );
if( (pB1->flags|pB2->flags) & MEM_Zero ){
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;
return pB1->u.nZero - n2;
}else{
if( !isZeroBlob(pB1) ) return +1;
return n1 - pB2->u.nZero;
}
}
c = memcmp(pB1->z, pB2->z, n1>n2 ? n2 : n1);
if( c ) return c;
return pB1->n - pB2->n;
return n1 - n2;
}
/*