aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-12-27 19:29:43 +0800
committerGitHub <noreply@github.com>2022-12-27 19:29:43 +0800
commit4aec442b5af5a1a7c3aa47626fee09452117575e (patch)
tree70b67a21476b363c16428cbdc0ea9a71e5357f98
parent146c428a533b649adbc95fc29b41af42624b6ece (diff)
parent45d9735aae9aea91420c849aace76ab72e9d3f2a (diff)
downloadrneovim-4aec442b5af5a1a7c3aa47626fee09452117575e.tar.gz
rneovim-4aec442b5af5a1a7c3aa47626fee09452117575e.tar.bz2
rneovim-4aec442b5af5a1a7c3aa47626fee09452117575e.zip
Merge pull request #21555 from zeertzjq/vim-9.0.1096
vim-patch:9.0.{1096,1097,1099,1100}: reallocating hashtab when the size didn't change
-rw-r--r--src/nvim/hashtab.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c
index fdbfdd7d77..042cb43ce4 100644
--- a/src/nvim/hashtab.c
+++ b/src/nvim/hashtab.c
@@ -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;
}
@@ -335,6 +335,13 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems)
}
bool newarray_is_small = newsize == HT_INIT_SIZE;
+
+ 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;
+ }
+
bool keep_smallarray = newarray_is_small
&& ht->ht_array == ht->ht_smallarray;