diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-07-26 21:26:34 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-07-26 21:26:34 +0200 |
commit | 7b73d7ebf71c9148c90a500116f25ec2314c7273 (patch) | |
tree | 1138f7122f2bb85454e2bdef9d9edfde06e4e6d4 /src/hashtab.c | |
parent | 9d5ffceb3fea247a88d4d3936e97b7f488aab6ff (diff) | |
download | vim-git-7b73d7ebf71c9148c90a500116f25ec2314c7273.tar.gz |
patch 8.1.1752: resizing hashtable is inefficientv8.1.1752
Problem: Resizing hashtable is inefficient.
Solution: Avoid resizing when the final size is predictable.
Diffstat (limited to 'src/hashtab.c')
-rw-r--r-- | src/hashtab.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/hashtab.c b/src/hashtab.c index ad018578b..450cf98f5 100644 --- a/src/hashtab.c +++ b/src/hashtab.c @@ -286,7 +286,6 @@ hash_lock(hashtab_T *ht) ++ht->ht_locked; } -#if 0 /* currently not used */ /* * Lock a hashtable at the specified number of entries. * Caller must make sure no more than "size" entries will be added. @@ -298,7 +297,6 @@ hash_lock_size(hashtab_T *ht, int size) (void)hash_may_resize(ht, size); ++ht->ht_locked; } -#endif /* * Unlock a hashtable: allow ht_array changes again. @@ -368,10 +366,10 @@ hash_may_resize( } else { - /* Use specified size. */ - if ((long_u)minitems < ht->ht_used) /* just in case... */ + // Use specified size. + if ((long_u)minitems < ht->ht_used) // just in case... minitems = (int)ht->ht_used; - minsize = minitems * 3 / 2; /* array is up to 2/3 full */ + minsize = (minitems * 3 + 1) / 2; // array is up to 2/3 full } newsize = HT_INIT_SIZE; |