"vscode:/vscode.git/clone" did not exist on "7ab9cba59bb8999d80d90571632fc37bac67c165"
Commit edb51958 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

first check if starting point is trivial (head or tail) before applying log(N) search

parent e74825c2
...@@ -5300,13 +5300,15 @@ static void zrangeGenericCommand(redisClient *c, int reverse) { ...@@ -5300,13 +5300,15 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
if (end >= llen) end = llen-1; if (end >= llen) end = llen-1;
rangelen = (end-start)+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) { if (reverse) {
ln = zslGetElementByRank(zsl, llen - start); ln = start == 0 ? zsl->tail : zslGetElementByRank(zsl, llen - start);
} else { } 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", addReplySds(c,sdscatprintf(sdsempty(),"*%d\r\n",
withscores ? (rangelen*2) : rangelen)); withscores ? (rangelen*2) : rangelen));
for (j = 0; j < rangelen; j++) { for (j = 0; j < rangelen; j++) {
......
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