summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-04-18 11:01:47 +0200
committerantirez <antirez@gmail.com>2017-04-18 11:01:47 +0200
commitc33493277a218c6a877158c585447dda912f4d19 (patch)
treeeb970d377124911d662364086d34c34d7ca766bc
parent0a942f17516c034a7868bbc68243b5f8a8d06f8d (diff)
downloadredis-c33493277a218c6a877158c585447dda912f4d19.tar.gz
Clarify why we save ziplist elements in revserse order.
Also get rid of variables that are now kinda redundant, since the dictionary iterator was removed. This is related to PR #3949.
-rw-r--r--src/rdb.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/rdb.c b/src/rdb.c
index c6a88081b..1a5a7b2c5 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -709,17 +709,23 @@ ssize_t rdbSaveObject(rio *rdb, robj *o) {
if ((n = rdbSaveLen(rdb,zsl->length)) == -1) return -1;
nwritten += n;
+ /* We save the skiplist elements from the greatest to the smallest
+ * (that's trivial since the elements are already ordered in the
+ * skiplist): this improves the load process, since the next loaded
+ * element will always be the smaller, so adding to the skiplist
+ * will always immediately stop at the head, making the insertion
+ * O(1) instead of O(log(N)). */
zskiplistNode *zn = zsl->tail;
while (zn != NULL) {
- sds ele = zn->ele;
- double *score = &zn->score;
-
- if ((n = rdbSaveRawString(rdb,(unsigned char*)ele,sdslen(ele)))
- == -1) return -1;
+ if ((n = rdbSaveRawString(rdb,
+ (unsigned char*)zn->ele,sdslen(zn->ele))) == -1)
+ {
+ return -1;
+ }
nwritten += n;
- if ((n = rdbSaveBinaryDoubleValue(rdb,*score)) == -1) return -1;
+ if ((n = rdbSaveBinaryDoubleValue(rdb,zn->score)) == -1)
+ return -1;
nwritten += n;
-
zn = zn->backward;
}
} else {