diff options
author | antirez <antirez@gmail.com> | 2015-02-06 10:48:13 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2015-02-11 10:52:27 +0100 |
commit | f25fdd6246f01b6ee3c0ce557e2911bc8c068518 (patch) | |
tree | 06844578fb3c9d5047f4186c06ea1367c6411a7c /src/dict.c | |
parent | 2385630d0d245482027e9e36c76d6f8675dd2f6b (diff) | |
download | redis-f25fdd6246f01b6ee3c0ce557e2911bc8c068518.tar.gz |
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.
Diffstat (limited to 'src/dict.c')
-rw-r--r-- | src/dict.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/dict.c b/src/dict.c index 3b23fbcd0..c8aaf1529 100644 --- a/src/dict.c +++ b/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. */ if (!dictIsRehashing(d)) return 0; - while(n--) { + while(n-- && d->ht[0].used != 0) { 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 * elements because ht[0].used != 0 */ 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->rehashidx++; } - /* Check again if we already rehashed the whole table... */ + + /* 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; } + + /* More to rehash... */ return 1; } |