mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
vim-patch:9.0.1100: a hashtab with many removed items is not cleaned up
Problem: A hashtab with many removed items is not cleaned up. Solution: Re-hash a hashtab even when the size didn't change if too many items were removed.d0883faac6
N/A patches for version.c: vim-patch:9.0.1099: trying to resize a hashtab may cause a problem Problem: Trying to resize a hashtab may cause a problem. Solution: Do not try to resize a hashtab before adding an item.81b7ecc5cb
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
9bab4b72ae
commit
45d9735aae
@ -292,6 +292,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems)
|
||||
#endif // ifdef HT_DEBUG
|
||||
|
||||
size_t minsize;
|
||||
const size_t oldsize = ht->ht_mask + 1;
|
||||
if (minitems == 0) {
|
||||
// Return quickly for small tables with at least two NULL items.
|
||||
// items are required for the lookup to decide a key isn't there.
|
||||
@ -304,7 +305,6 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems)
|
||||
// removed items, so that they get cleaned up).
|
||||
// Shrink the array when it's less than 1/5 full. When growing it is
|
||||
// at least 1/4 full (avoids repeated grow-shrink operations)
|
||||
size_t oldsize = ht->ht_mask + 1;
|
||||
if ((ht->ht_filled * 3 < oldsize * 2) && (ht->ht_used > oldsize / 5)) {
|
||||
return;
|
||||
}
|
||||
@ -336,8 +336,9 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems)
|
||||
|
||||
bool newarray_is_small = newsize == HT_INIT_SIZE;
|
||||
|
||||
if (!newarray_is_small && newsize == ht->ht_mask + 1) {
|
||||
// the hashtab is already at the desired size, bail out
|
||||
if (!newarray_is_small && newsize == oldsize && ht->ht_filled * 3 < oldsize * 2) {
|
||||
// The hashtab is already at the desired size, and there are not too
|
||||
// many removed items, bail out.
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user