]> git.saurik.com Git - redis.git/blobdiff - src/t_list.c
Merge pull request #79 from annulen/mac_ppc
[redis.git] / src / t_list.c
index 0690fd2fa913a65dcfee23fb1e7cad48f4cd9db8..71436198d7859ccff9e8c27f3ccf4376232dea98 100644 (file)
@@ -519,7 +519,12 @@ void lrangeCommand(redisClient *c) {
             p = ziplistNext(o->ptr,p);
         }
     } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) {
-        listNode *ln = listIndex(o->ptr,start);
+        listNode *ln;
+
+        /* If we are nearest to the end of the list, reach the element
+         * starting from tail and going backward, as it is faster. */
+        if (start > llen/2) start -= llen;
+        ln = listIndex(o->ptr,start);
 
         while(rangelen--) {
             addReplyBulk(c,ln->value);