Unverified Commit 17904780 authored by WangYu's avatar WangYu Committed by GitHub
Browse files

skip the rehashed entries in dictNext (#12386)



If dict is rehashing, the  entries in the head of table[0] is moved to table[1]
and all entries in `table[0][0:rehashidx]` is NULL.

`dictNext` start looking for non-NULL entry from table 0 index 0, and the first call
of `dictNext` on a rehashing dict will Iterate many times to skip those NULL entries.
We can easily skip those entries by setting `iter->index` as `iter->d->rehashidx` when
dict is rehashing and it's the first call of dictNext (`iter->index == -1 && iter->table == 0`).
Co-authored-by: default avatarsundb <sundbcn@gmail.com>
parent 965dc90b
...@@ -950,6 +950,11 @@ dictEntry *dictNext(dictIterator *iter) ...@@ -950,6 +950,11 @@ dictEntry *dictNext(dictIterator *iter)
dictPauseRehashing(iter->d); dictPauseRehashing(iter->d);
else else
iter->fingerprint = dictFingerprint(iter->d); iter->fingerprint = dictFingerprint(iter->d);
/* skip the rehashed slots in table[0] */
if (dictIsRehashing(iter->d)) {
iter->index = iter->d->rehashidx - 1;
}
} }
iter->index++; iter->index++;
if (iter->index >= (long) DICTHT_SIZE(iter->d->ht_size_exp[iter->table])) { if (iter->index >= (long) DICTHT_SIZE(iter->d->ht_size_exp[iter->table])) {
......
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