dict.c: avoid code repetition in dictRehash().
Avoid code repetition introduced with PR #2367, also fixes the return value to always return 0 if there is nothing more to rehash.
This commit is contained in:
parent
2385630d0d
commit
f25fdd6246
17
src/dict.c
17
src/dict.c
@ -246,18 +246,9 @@ int dictRehash(dict *d, int n) {
|
|||||||
int empty_visits = n*10; /* Max number of empty buckets to visit. */
|
int empty_visits = n*10; /* Max number of empty buckets to visit. */
|
||||||
if (!dictIsRehashing(d)) return 0;
|
if (!dictIsRehashing(d)) return 0;
|
||||||
|
|
||||||
while(n--) {
|
while(n-- && d->ht[0].used != 0) {
|
||||||
dictEntry *de, *nextde;
|
dictEntry *de, *nextde;
|
||||||
|
|
||||||
/* Check if we already rehashed the whole table... */
|
|
||||||
if (d->ht[0].used == 0) {
|
|
||||||
zfree(d->ht[0].table);
|
|
||||||
d->ht[0] = d->ht[1];
|
|
||||||
_dictReset(&d->ht[1]);
|
|
||||||
d->rehashidx = -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Note that rehashidx can't overflow as we are sure there are more
|
/* Note that rehashidx can't overflow as we are sure there are more
|
||||||
* elements because ht[0].used != 0 */
|
* elements because ht[0].used != 0 */
|
||||||
assert(d->ht[0].size > (unsigned long)d->rehashidx);
|
assert(d->ht[0].size > (unsigned long)d->rehashidx);
|
||||||
@ -282,13 +273,17 @@ int dictRehash(dict *d, int n) {
|
|||||||
d->ht[0].table[d->rehashidx] = NULL;
|
d->ht[0].table[d->rehashidx] = NULL;
|
||||||
d->rehashidx++;
|
d->rehashidx++;
|
||||||
}
|
}
|
||||||
/* Check again if we already rehashed the whole table... */
|
|
||||||
|
/* Check if we already rehashed the whole table... */
|
||||||
if (d->ht[0].used == 0) {
|
if (d->ht[0].used == 0) {
|
||||||
zfree(d->ht[0].table);
|
zfree(d->ht[0].table);
|
||||||
d->ht[0] = d->ht[1];
|
d->ht[0] = d->ht[1];
|
||||||
_dictReset(&d->ht[1]);
|
_dictReset(&d->ht[1]);
|
||||||
d->rehashidx = -1;
|
d->rehashidx = -1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* More to rehash... */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user