From 3c68de9b0107a0a15eef09edf86464d1434048e7 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 2 Feb 2010 12:05:15 +0100 Subject: [PATCH] faster Set loading time from .rdb file resizing the hash table to the right size before loading elements --- redis.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/redis.c b/redis.c index 36055c4c..e095e695 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;