Avoid redundant lpGet to boost quicklistCompare (#11533)

`lpCompare()` in `quicklistCompare()` will call `lpGet()` again, which
would be a waste.
The change will result in a boost for all commands that use
`quicklistCompre()`, including `linsert`, `lpos` and `lrem`.
This commit is contained in:
debing.sun 2024-10-30 08:45:25 +08:00 committed by GitHub
parent 2ec78d262d
commit 4b29be3f36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1244,10 +1244,17 @@ int quicklistDelRange(quicklist *quicklist, const long start,
/* compare between a two entries */
int quicklistCompare(quicklistEntry* entry, unsigned char *p2, const size_t p2_len) {
if (unlikely(QL_NODE_IS_PLAIN(entry->node))) {
if (entry->value) {
return ((entry->sz == p2_len) && (memcmp(entry->value, p2, p2_len) == 0));
} else {
/* We use string2ll() to get an integer representation of the
* string 'p2' and compare it to 'entry->longval', it's much
* faster than convert integer to string and comparing. */
long long sval;
if (string2ll((const char*)p2, p2_len, &sval))
return entry->longval == sval;
}
return lpCompare(entry->zi, p2, p2_len);
return 0;
}
/* Returns a quicklist iterator 'iter'. After the initialization every