From bbfe232f607f10655b6f9bf1d8f91830bb3ba413 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 10 Mar 2011 16:17:14 +0100 Subject: [PATCH] Make zzlLength take a ziplist argument --- src/t_zset.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/t_zset.c b/src/t_zset.c index 3c9ede1c0..0a35f3925 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -449,9 +449,7 @@ int zzlCompareElements(unsigned char *eptr, unsigned char *cstr, unsigned int cl return cmp; } -unsigned int zzlLength(robj *zobj) { - unsigned char *zl = zobj->ptr; - redisAssert(zobj->encoding == REDIS_ENCODING_ZIPLIST); +unsigned int zzlLength(unsigned char *zl) { return ziplistLen(zl)/2; } @@ -720,7 +718,7 @@ unsigned long zzlDeleteRangeByRank(robj *zobj, unsigned int start, unsigned int int zsLength(robj *zobj) { int length = -1; if (zobj->encoding == REDIS_ENCODING_ZIPLIST) { - length = zzlLength(zobj); + length = zzlLength(zobj->ptr); } else if (zobj->encoding == REDIS_ENCODING_RAW) { length = ((zset*)zobj->ptr)->zsl->length; } else { @@ -874,7 +872,7 @@ void zaddGenericCommand(redisClient *c, int incr) { /* Optimize: check if the element is too large or the list becomes * too long *before* executing zzlInsert. */ redisAssert(zzlInsert(zobj,ele,score) == REDIS_OK); - if (zzlLength(zobj) > server.zset_max_ziplist_entries) + if (zzlLength(zobj->ptr) > server.zset_max_ziplist_entries) zsConvert(zobj,REDIS_ENCODING_RAW); if (sdslen(ele->ptr) > server.zset_max_ziplist_value) zsConvert(zobj,REDIS_ENCODING_RAW); @@ -965,7 +963,7 @@ void zremCommand(redisClient *c) { if ((eptr = zzlFind(zobj,ele,NULL)) != NULL) { redisAssert(zzlDelete(zobj,eptr) == REDIS_OK); - if (zzlLength(zobj) == 0) dbDelete(c->db,key); + if (zzlLength(zobj->ptr) == 0) dbDelete(c->db,key); } else { addReply(c,shared.czero); return;