mirror of https://mirror.osredm.com/root/redis.git
Add length check before content comparison in equalStringObjects (#14062)
### 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
|
||||
* 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. */
|
||||
int equalStringObjects(robj *a, robj *b) {
|
||||
if (a->encoding == OBJ_ENCODING_INT &&
|
||||
|
@ -989,6 +989,11 @@ int equalStringObjects(robj *a, robj *b) {
|
|||
* long is the same. */
|
||||
return a->ptr == b->ptr;
|
||||
} else {
|
||||
if (sdsEncodedObject(a) && sdsEncodedObject(b)
|
||||
&& sdslen(a->ptr) != sdslen(b->ptr))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return compareStringObjects(a,b) == 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue