Unverified Commit 4b29be3f authored by debing.sun's avatar debing.sun Committed by GitHub
Browse files

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`.
parent 2ec78d26
...@@ -1244,10 +1244,17 @@ int quicklistDelRange(quicklist *quicklist, const long start, ...@@ -1244,10 +1244,17 @@ int quicklistDelRange(quicklist *quicklist, const long start,
/* compare between a two entries */ /* compare between a two entries */
int quicklistCompare(quicklistEntry* entry, unsigned char *p2, const size_t p2_len) { 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)); 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 /* Returns a quicklist iterator 'iter'. After the initialization every
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment