summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-09-07 12:41:23 +0200
committerantirez <antirez@gmail.com>2016-09-07 15:28:46 +0200
commit5d4cd43ef88be4ba39af34494c65223f4641ef2a (patch)
treef6304e4775fad3ac7f20d015cd9abff2828316f7
parent9554fd5ab0dd46bbaa117e35a73b4716133c452b (diff)
downloadredis-5d4cd43ef88be4ba39af34494c65223f4641ef2a.tar.gz
dict.c better dictPushEntry initial index strategy.
-rw-r--r--src/dict.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/dict.c b/src/dict.c
index a304ee64a..551f83025 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -182,9 +182,14 @@ dictEntry *dictPushEntry(dictEntryVector **table, unsigned int idx, const void *
memset(dv->entry+dv->used,0,sizeof(dictEntry)*dv->free);
} else {
uint32_t entries = dv->used+dv->free;
- uint32_t j;
- for (j = 0; j < entries; j++) {
+ /* Start iterating with j set to the number of buckets already
+ * 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;
+ j = (j+1)%entries;
}
he = dv->entry+j;
dv->used++;