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: sundb <sundbcn@gmail.com>
This commit is contained in:
parent
965dc90b72
commit
17904780ae
@ -950,6 +950,11 @@ dictEntry *dictNext(dictIterator *iter)
|
||||
dictPauseRehashing(iter->d);
|
||||
else
|
||||
iter->fingerprint = dictFingerprint(iter->d);
|
||||
|
||||
/* skip the rehashed slots in table[0] */
|
||||
if (dictIsRehashing(iter->d)) {
|
||||
iter->index = iter->d->rehashidx - 1;
|
||||
}
|
||||
}
|
||||
iter->index++;
|
||||
if (iter->index >= (long) DICTHT_SIZE(iter->d->ht_size_exp[iter->table])) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user