1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-09-02 12:21:26 +03:00

Performance improvement to the sqlite3MemCompare() routine by factoring out

sqlite3BlobCompare().

FossilOrigin-Name: 20ed2321b09ba076e50f9fc2f42c135b25746d72
This commit is contained in:
drh
2014-09-16 03:24:43 +00:00
parent b6dea49f3d
commit 982ff72f0f
3 changed files with 21 additions and 14 deletions

View File

@@ -3319,6 +3319,18 @@ static int vdbeCompareMemString(
}
}
/*
** 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);
if( c ) return c;
return pB1->n - pB2->n;
}
/*
** Compare the values contained by the two memory cells, returning
** negative, zero or positive if pMem1 is less than, equal to, or greater
@@ -3329,7 +3341,6 @@ static int vdbeCompareMemString(
** Two NULL values are considered equal by this function.
*/
int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
int rc;
int f1, f2;
int combined_flags;
@@ -3404,11 +3415,7 @@ int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
}
/* Both values must be blobs. Compare using memcmp(). */
rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
if( rc==0 ){
rc = pMem1->n - pMem2->n;
}
return rc;
return sqlite3BlobCompare(pMem1, pMem2);
}