diff options
author | ZheNing Hu <adlternative@gmail.com> | 2021-04-25 15:53:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-25 10:53:53 +0300 |
commit | 828ae842b95654f66b03e786588c97d7a0c386a2 (patch) | |
tree | aae1e79afdc8d6aa5be8cb066f2e08ecab222a42 /src/ziplist.c | |
parent | f29a0b9351e61ae16a7cfeaa2c05c409221988ca (diff) | |
download | redis-828ae842b95654f66b03e786588c97d7a0c386a2.tar.gz |
Improve ziplistRandomPairs code logic (#8851)
After sorting, each item in picks is sorted according
to its index.
In the original code logic, we traverse from the first
element of ziplist until `zipindex == picks[pickindex].index`.
We may be able to start directly in `picks[0].index`,
this will bring small performance improvement.
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Diffstat (limited to 'src/ziplist.c')
-rw-r--r-- | src/ziplist.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/ziplist.c b/src/ziplist.c index 85cb50991..89270dd93 100644 --- a/src/ziplist.c +++ b/src/ziplist.c @@ -1601,8 +1601,8 @@ void ziplistRandomPairs(unsigned char *zl, unsigned int count, ziplistEntry *key qsort(picks, count, sizeof(rand_pick), uintCompare); /* fetch the elements form the ziplist into a output array respecting the original order. */ - unsigned int zipindex = 0, pickindex = 0; - p = ziplistIndex(zl, 0); + unsigned int zipindex = picks[0].index, pickindex = 0; + p = ziplistIndex(zl, zipindex); while (ziplistGet(p, &key, &klen, &klval) && pickindex < count) { p = ziplistNext(zl, p); assert(ziplistGet(p, &value, &vlen, &vlval)); |