faster Set loading time from .rdb file resizing the hash table to the right size before loading elements

This commit is contained in:
antirez 2010-02-02 12:05:15 +01:00
parent 9651a78787
commit 3c68de9b01

View File

@ -3335,6 +3335,10 @@ static robj *rdbLoadObject(int type, FILE *fp) {
if ((listlen = rdbLoadLen(fp,NULL)) == REDIS_RDB_LENERR) return NULL; if ((listlen = rdbLoadLen(fp,NULL)) == REDIS_RDB_LENERR) return NULL;
o = (type == REDIS_LIST) ? createListObject() : createSetObject(); 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 */ /* Load every single element of the list/set */
while(listlen--) { while(listlen--) {
robj *ele; robj *ele;