summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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++;