X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/aa549962a4227f8732e3c9448ba8910160ec3ec4..6205b46387ef47e0fcb9bd6c9f371c9eb5cdd7e5:/ziplist.c diff --git a/ziplist.c b/ziplist.c index 4907d07b..3dd3c1e8 100644 --- a/ziplist.c +++ b/ziplist.c @@ -388,6 +388,24 @@ unsigned int ziplistCompare(unsigned char *p, unsigned char *entry, unsigned int } } +/* Return length of ziplist. */ +unsigned int ziplistLen(unsigned char *zl) { + unsigned int len = 0; + if (ZIPLIST_LENGTH(zl) < ZIP_BIGLEN) { + len = ZIPLIST_LENGTH(zl); + } else { + unsigned char *p = zl+ZIPLIST_HEADER_SIZE; + while (*p != ZIP_END) { + p += zipRawEntryLength(p); + len++; + } + + /* Re-store length if small enough */ + if (len < ZIP_BIGLEN) ZIPLIST_LENGTH(zl) = len; + } + return len; +} + void ziplistRepr(unsigned char *zl) { unsigned char *p, encoding; unsigned int l, lsize;