diff --git a/redis.c b/redis.c index 36055c4c92425ea6d6af3d1ce91e89ca55dc5829..e095e6952ec6351b46f7d984a185f3b24d3a2ba1 100644 --- a/redis.c +++ b/redis.c @@ -3335,6 +3335,10 @@ static robj *rdbLoadObject(int type, FILE *fp) { if ((listlen = rdbLoadLen(fp,NULL)) == REDIS_RDB_LENERR) return NULL; o = (type == REDIS_LIST) ? createListObject() : createSetObject(); + /* It's faster to expand the dict to the right size asap in order + * to avoid rehashing */ + if (type == REDIS_SET && listlen > DICT_HT_INITIAL_SIZE) + dictExpand(o->ptr,listlen); /* Load every single element of the list/set */ while(listlen--) { robj *ele;