diff options
author | antirez <antirez@gmail.com> | 2017-04-18 11:01:47 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2017-04-18 11:01:47 +0200 |
commit | c33493277a218c6a877158c585447dda912f4d19 (patch) | |
tree | eb970d377124911d662364086d34c34d7ca766bc | |
parent | 0a942f17516c034a7868bbc68243b5f8a8d06f8d (diff) | |
download | redis-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.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -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 { |