Backport patch: object swappability for encoded sorted sets

This commit is contained in:
Pieter Noordhuis 2011-03-22 16:35:50 +01:00
parent 476f044db6
commit 724376a0df

View File

@ -368,7 +368,6 @@ double computeObjectSwappability(robj *o) {
listNode *ln; listNode *ln;
dict *d; dict *d;
struct dictEntry *de; struct dictEntry *de;
int z;
if (minage <= 0) return 0; if (minage <= 0) return 0;
switch(o->type) { switch(o->type) {
@ -395,23 +394,34 @@ double computeObjectSwappability(robj *o) {
} }
break; break;
case REDIS_SET: case REDIS_SET:
case REDIS_ZSET: if (o->encoding == REDIS_ENCODING_INTSET) {
z = (o->type == REDIS_ZSET);
d = z ? ((zset*)o->ptr)->dict : o->ptr;
if (!z && o->encoding == REDIS_ENCODING_INTSET) {
intset *is = o->ptr; intset *is = o->ptr;
asize = sizeof(*is)+is->encoding*is->length; asize = sizeof(*is)+is->encoding*is->length;
} else { } else {
d = o->ptr;
asize = sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d)); asize = sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d));
if (z) asize += sizeof(zset)-sizeof(dict);
if (dictSize(d)) { if (dictSize(d)) {
de = dictGetRandomKey(d); de = dictGetRandomKey(d);
ele = dictGetEntryKey(de); ele = dictGetEntryKey(de);
elesize = (ele->encoding == REDIS_ENCODING_RAW) ? elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
(sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o); (sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
asize += (sizeof(struct dictEntry)+elesize)*dictSize(d); asize += (sizeof(struct dictEntry)+elesize)*dictSize(d);
if (z) asize += sizeof(zskiplistNode)*dictSize(d); }
}
break;
case REDIS_ZSET:
if (o->encoding == REDIS_ENCODING_ZIPLIST) {
asize = sizeof(*o)+(ziplistSize(o->ptr) / 2);
} else {
d = ((zset*)o->ptr)->dict;
asize = sizeof(zset)+(sizeof(struct dictEntry*)*dictSlots(d));
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);
asize += sizeof(zskiplistNode)*dictSize(d);
} }
} }
break; break;