mirror of https://github.com/redis/redis.git
Add length check before content comparison in equalStringObjects (#14062)
CI / test-ubuntu-latest (push) Has been cancelled
Details
CI / test-sanitizer-address (push) Has been cancelled
Details
CI / build-debian-old (push) Has been cancelled
Details
CI / build-macos-latest (push) Has been cancelled
Details
CI / build-32bit (push) Has been cancelled
Details
CI / build-libc-malloc (push) Has been cancelled
Details
CI / build-centos-jemalloc (push) Has been cancelled
Details
CI / build-old-chain-jemalloc (push) Has been cancelled
Details
Codecov / code-coverage (push) Has been cancelled
Details
External Server Tests / test-external-standalone (push) Has been cancelled
Details
External Server Tests / test-external-cluster (push) Has been cancelled
Details
External Server Tests / test-external-nodebug (push) Has been cancelled
Details
Spellcheck / Spellcheck (push) Has been cancelled
Details
CI / test-ubuntu-latest (push) Has been cancelled
Details
CI / test-sanitizer-address (push) Has been cancelled
Details
CI / build-debian-old (push) Has been cancelled
Details
CI / build-macos-latest (push) Has been cancelled
Details
CI / build-32bit (push) Has been cancelled
Details
CI / build-libc-malloc (push) Has been cancelled
Details
CI / build-centos-jemalloc (push) Has been cancelled
Details
CI / build-old-chain-jemalloc (push) Has been cancelled
Details
Codecov / code-coverage (push) Has been cancelled
Details
External Server Tests / test-external-standalone (push) Has been cancelled
Details
External Server Tests / test-external-cluster (push) Has been cancelled
Details
External Server Tests / test-external-nodebug (push) Has been cancelled
Details
Spellcheck / Spellcheck (push) Has been cancelled
Details
### Issue Previously, even when only string equality needed to be determined, the comparison logic still performed unnecessary `memcmp()` calls to check string ordering, even if the lengths were not equal. ### Change This PR add length check before content comparison in `equalStringObjects` function. --------- Co-authored-by: debing.sun <debing.sun@redis.com>
This commit is contained in:
parent
7998a2a05f
commit
35e15962b5
|
@ -980,7 +980,7 @@ int collateStringObjects(const robj *a, const robj *b) {
|
||||||
|
|
||||||
/* Equal string objects return 1 if the two objects are the same from the
|
/* Equal string objects return 1 if the two objects are the same from the
|
||||||
* point of view of a string comparison, otherwise 0 is returned. Note that
|
* point of view of a string comparison, otherwise 0 is returned. Note that
|
||||||
* this function is faster then checking for (compareStringObject(a,b) == 0)
|
* this function is faster than checking for (compareStringObject(a,b) == 0)
|
||||||
* because it can perform some more optimization. */
|
* because it can perform some more optimization. */
|
||||||
int equalStringObjects(robj *a, robj *b) {
|
int equalStringObjects(robj *a, robj *b) {
|
||||||
if (a->encoding == OBJ_ENCODING_INT &&
|
if (a->encoding == OBJ_ENCODING_INT &&
|
||||||
|
@ -989,6 +989,11 @@ int equalStringObjects(robj *a, robj *b) {
|
||||||
* long is the same. */
|
* long is the same. */
|
||||||
return a->ptr == b->ptr;
|
return a->ptr == b->ptr;
|
||||||
} else {
|
} else {
|
||||||
|
if (sdsEncodedObject(a) && sdsEncodedObject(b)
|
||||||
|
&& sdslen(a->ptr) != sdslen(b->ptr))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return compareStringObjects(a,b) == 0;
|
return compareStringObjects(a,b) == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue