mirror of
https://github.com/fluencelabs/redis
synced 2025-03-18 16:40:50 +00:00
first check if starting point is trivial (head or tail) before applying log(N) search
This commit is contained in:
parent
e74825c24f
commit
edb519581a
8
redis.c
8
redis.c
@ -5300,13 +5300,15 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
|
||||
if (end >= llen) end = llen-1;
|
||||
rangelen = (end-start)+1;
|
||||
|
||||
/* Return the result in form of a multi-bulk reply */
|
||||
/* check if starting point is trivial, before searching
|
||||
* the element in log(N) time */
|
||||
if (reverse) {
|
||||
ln = zslGetElementByRank(zsl, llen - start);
|
||||
ln = start == 0 ? zsl->tail : zslGetElementByRank(zsl, llen - start);
|
||||
} else {
|
||||
ln = zslGetElementByRank(zsl, start + 1);
|
||||
ln = start == 0 ? zsl->header->forward[0] : zslGetElementByRank(zsl, start + 1);
|
||||
}
|
||||
|
||||
/* Return the result in form of a multi-bulk reply */
|
||||
addReplySds(c,sdscatprintf(sdsempty(),"*%d\r\n",
|
||||
withscores ? (rangelen*2) : rangelen));
|
||||
for (j = 0; j < rangelen; j++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user