Commit 5d4cd43e authored by antirez's avatar antirez
Browse files

dict.c better dictPushEntry initial index strategy.

parent 9554fd5a
...@@ -182,9 +182,14 @@ dictEntry *dictPushEntry(dictEntryVector **table, unsigned int idx, const void * ...@@ -182,9 +182,14 @@ dictEntry *dictPushEntry(dictEntryVector **table, unsigned int idx, const void *
memset(dv->entry+dv->used,0,sizeof(dictEntry)*dv->free); memset(dv->entry+dv->used,0,sizeof(dictEntry)*dv->free);
} else { } else {
uint32_t entries = dv->used+dv->free; uint32_t entries = dv->used+dv->free;
uint32_t j; /* Start iterating with j set to the number of buckets already
for (j = 0; j < entries; j++) { * used: it is likely there are empty buckets at the end after
* a reallocation of the entries vector. */
uint32_t j = dv->used;
uint32_t i = entries;
while (i--) {
if (dv->entry[j].key == NULL) break; if (dv->entry[j].key == NULL) break;
j = (j+1)%entries;
} }
he = dv->entry+j; he = dv->entry+j;
dv->used++; dv->used++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment