diff options
author | antirez <antirez@gmail.com> | 2016-09-06 16:55:48 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2016-09-07 15:28:46 +0200 |
commit | 96224f750fb82f53402553722fcaf22ae71de437 (patch) | |
tree | 87aa25d1a7e58e76f8fa6eaa5da3c8d0e5a56d57 | |
parent | 976a7d231f4aac3d16bb0d7cfc1c7071213000f0 (diff) | |
download | redis-96224f750fb82f53402553722fcaf22ae71de437.tar.gz |
dict.c clustered slot prealloc.
-rw-r--r-- | src/dict.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/dict.c b/src/dict.c index 79c3935c1..4a493cf04 100644 --- a/src/dict.c +++ b/src/dict.c @@ -60,7 +60,7 @@ * prevented: a hash table is still allowed to grow if the ratio between * the number of elements and the buckets > dict_force_resize_ratio. */ static int dict_can_resize = 1; -static unsigned int dict_resize_ratio = 20; +static unsigned int dict_resize_ratio = 10; static unsigned int dict_force_resize_ratio = 60; /* -------------------------- private prototypes ---------------------------- */ @@ -153,14 +153,20 @@ dictEntry *dictPushEntry(dictEntryVector **table, unsigned int idx, const void * dictEntry *he; if (dv == NULL) { - dv = table[idx] = zmalloc(sizeof(dictEntryVector)+sizeof(dictEntry)); + int initlen = dict_resize_ratio/4; + if (initlen == 0) initlen = 1; + dv = table[idx] = + zcalloc(sizeof(dictEntryVector)+sizeof(dictEntry)*initlen); dv->used = 1; - dv->free = 0; + dv->free = initlen-1; he = dv->entry; } else if (dv->free == 0) { - dv = table[idx] = zrealloc(table[idx],sizeof(dictEntryVector)+sizeof(dictEntry)*(dv->used+1)); + int newlen = (dv->used+dv->free)*2; + dv = table[idx] = zrealloc(table[idx],sizeof(dictEntryVector)+sizeof(dictEntry)*newlen); he = dv->entry+dv->used; dv->used++; + dv->free = newlen - dv->used; + memset(dv->entry+dv->used,0,sizeof(dictEntry)*dv->free); } else { uint32_t entries = dv->used+dv->free; uint32_t j; |