]> git.saurik.com Git - redis.git/commitdiff
computeObjectSwappability is now able to compute swappability for intset encoded...
authorantirez <antirez@gmail.com>
Thu, 26 Aug 2010 10:28:53 +0000 (12:28 +0200)
committerantirez <antirez@gmail.com>
Thu, 26 Aug 2010 10:28:53 +0000 (12:28 +0200)
src/vm.c

index 0ccc5fe22658e8381cb4c7adfb0f40b0f7f82c11..a34387521d0cac989b73fe9f7021dd53ba917a3b 100644 (file)
--- a/src/vm.c
+++ b/src/vm.c
@@ -395,15 +395,20 @@ double computeObjectSwappability(robj *o) {
         z = (o->type == REDIS_ZSET);
         d = z ? ((zset*)o->ptr)->dict : o->ptr;
 
-        asize = sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d));
-        if (z) asize += sizeof(zset)-sizeof(dict);
-        if (dictSize(d)) {
-            de = dictGetRandomKey(d);
-            ele = dictGetEntryKey(de);
-            elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
-                            (sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
-            asize += (sizeof(struct dictEntry)+elesize)*dictSize(d);
-            if (z) asize += sizeof(zskiplistNode)*dictSize(d);
+        if (!z && o->encoding == REDIS_ENCODING_INTSET) {
+            intset *is = o->ptr;
+            asize = sizeof(*is)+is->encoding*is->length;
+        } else {
+            asize = sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d));
+            if (z) asize += sizeof(zset)-sizeof(dict);
+            if (dictSize(d)) {
+                de = dictGetRandomKey(d);
+                ele = dictGetEntryKey(de);
+                elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
+                                (sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
+                asize += (sizeof(struct dictEntry)+elesize)*dictSize(d);
+                if (z) asize += sizeof(zskiplistNode)*dictSize(d);
+            }
         }
         break;
     case REDIS_HASH: