From 93f24403f8cc760ff47979c596976b53a8b16358 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 24 Aug 2022 22:49:25 +0100 Subject: refactor: pre-incr to post-incr --- src/nvim/hashtab.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 951e72ea52..308f64f011 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -67,7 +67,7 @@ void hash_clear(hashtab_T *ht) void hash_clear_all(hashtab_T *ht, unsigned int off) { size_t todo = ht->ht_used; - for (hashitem_T *hi = ht->ht_array; todo > 0; ++hi) { + for (hashitem_T *hi = ht->ht_array; todo > 0; hi++) { if (!HASHITEM_EMPTY(hi)) { xfree(hi->hi_key - off); todo--; @@ -356,7 +356,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) hash_T newmask = newsize - 1; size_t todo = ht->ht_used; - for (hashitem_T *olditem = oldarray; todo > 0; ++olditem) { + for (hashitem_T *olditem = oldarray; todo > 0; olditem++) { if (HASHITEM_EMPTY(olditem)) { continue; } -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/hashtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 308f64f011..3d0ab192b9 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -87,7 +87,7 @@ void hash_clear_all(hashtab_T *ht, unsigned int off) /// is changed in any way. hashitem_T *hash_find(const hashtab_T *const ht, const char *const key) { - return hash_lookup(ht, key, STRLEN(key), hash_hash((char_u *)key)); + return hash_lookup(ht, key, strlen(key), hash_hash((char_u *)key)); } /// Like hash_find, but key is not NUL-terminated -- cgit From df646572c53f55268a5dbb61628d7c3b302d5663 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 30 Sep 2022 09:53:52 +0200 Subject: docs: fix typos (#20394) Co-authored-by: Raphael Co-authored-by: smjonas Co-authored-by: zeertzjq --- src/nvim/hashtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 3d0ab192b9..32d67621db 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -265,7 +265,7 @@ void hash_unlock(hashtab_T *ht) hash_may_resize(ht, 0); } -/// Resize hastable (new size can be given or automatically computed). +/// Resize hashtable (new size can be given or automatically computed). /// /// @param minitems Minimum number of items the new table should hold. /// If zero, new size will depend on currently used items: -- cgit From 09dffb9db7d16496e55e86f78ab60241533d86f6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 9 Oct 2022 08:21:52 -0400 Subject: docs: various #12823 - increase python line-length limit from 88 => 100. - gen_help_html: fix bug in "tag" case (tbl_count => tbl_contains) ref #15632 fix #18215 fix #18479 fix #20527 fix #20532 Co-authored-by: Ben Weedon --- src/nvim/hashtab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 32d67621db..1ebac603c2 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -194,7 +194,7 @@ void hash_debug_results(void) #endif // ifdef HT_DEBUG } -/// Add item for key "key" to hashtable "ht". +/// Add (empty) item for key `key` to hashtable `ht`. /// /// @param key Pointer to the key for the new item. The key has to be contained /// in the new item (@see hashitem_T). Must not be NULL. -- cgit From bd22585061b66d7f71d4832b4a81e950b3c9d19d Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/hashtab.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 1ebac603c2..e3a5f40492 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -201,15 +201,15 @@ void hash_debug_results(void) /// /// @return OK if success. /// FAIL if key already present -int hash_add(hashtab_T *ht, char_u *key) +int hash_add(hashtab_T *ht, char *key) { - hash_T hash = hash_hash(key); - hashitem_T *hi = hash_lookup(ht, (const char *)key, STRLEN(key), hash); + hash_T hash = hash_hash((char_u *)key); + hashitem_T *hi = hash_lookup(ht, key, strlen(key), hash); if (!HASHITEM_EMPTY(hi)) { internal_error("hash_add()"); return FAIL; } - hash_add_item(ht, hi, key, hash); + hash_add_item(ht, hi, (char_u *)key, hash); return OK; } @@ -226,7 +226,7 @@ void hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash) if (hi->hi_key == NULL) { ht->ht_filled++; } - hi->hi_key = key; + hi->hi_key = (char *)key; hi->hi_hash = hash; // When the space gets low may resize the array. @@ -449,5 +449,5 @@ hash_T hash_hash_len(const char *key, const size_t len) const char_u *_hash_key_removed(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - return HI_KEY_REMOVED; + return (char_u *)HI_KEY_REMOVED; } -- cgit From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/hashtab.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index e3a5f40492..31dc6f5bd4 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -140,7 +140,7 @@ hashitem_T *hash_lookup(const hashtab_T *const ht, const char *const key, const if (hi->hi_key == HI_KEY_REMOVED) { freeitem = hi; } else if ((hi->hi_hash == hash) - && (STRNCMP(hi->hi_key, key, key_len) == 0) + && (strncmp(hi->hi_key, key, key_len) == 0) && hi->hi_key[key_len] == NUL) { return hi; } @@ -166,7 +166,7 @@ hashitem_T *hash_lookup(const hashtab_T *const ht, const char *const key, const if ((hi->hi_hash == hash) && (hi->hi_key != HI_KEY_REMOVED) - && (STRNCMP(hi->hi_key, key, key_len) == 0) + && (strncmp(hi->hi_key, key, key_len) == 0) && hi->hi_key[key_len] == NUL) { return hi; } -- cgit From 73a6000120e64c534eb3545952422c4dc17972fe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 17 Dec 2022 08:47:30 +0800 Subject: vim-patch:8.2.1209: Vim9: test failure Problem: Vim9: test failure. Solution: Add missing changes to hashtab. https://github.com/vim/vim/commit/21c16f868d725fffc8fa36620cba33dd5f2ed576 Co-authored-by: Bram Moolenaar --- src/nvim/hashtab.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 31dc6f5bd4..fdbfdd7d77 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -223,6 +223,7 @@ int hash_add(hashtab_T *ht, char *key) void hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash) { ht->ht_used++; + ht->ht_changed++; if (hi->hi_key == NULL) { ht->ht_filled++; } @@ -242,6 +243,7 @@ void hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash) void hash_remove(hashtab_T *ht, hashitem_T *hi) { ht->ht_used--; + ht->ht_changed++; hi->hi_key = HI_KEY_REMOVED; hash_may_resize(ht, 0); } @@ -384,6 +386,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) ht->ht_array = newarray; ht->ht_mask = newmask; ht->ht_filled = ht->ht_used; + ht->ht_changed++; } #define HASH_CYCLE_BODY(hash, p) \ -- cgit From 59012a18e190532f673e72899b3e005e9792d8f8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Dec 2022 18:49:24 +0800 Subject: vim-patch:9.0.1096: reallocating hashtab when the size didn't change Problem: Reallocating hashtab when the size didn't change. Solution: Bail out when the hashtab is already the desired size. https://github.com/vim/vim/commit/71d53e7c579b8af44083142ea3894b455947ad81 Co-authored-by: Bram Moolenaar --- src/nvim/hashtab.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index fdbfdd7d77..448e78ab07 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -334,6 +334,11 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) assert(newsize != 0); } + // bail out if the hashtab is already at the desired size + if (newsize == ht->ht_mask + 1) { + return; + } + bool newarray_is_small = newsize == HT_INIT_SIZE; bool keep_smallarray = newarray_is_small && ht->ht_array == ht->ht_smallarray; -- cgit From 9bab4b72ae4c996751a83badc1c2a183c7cbf5d2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Dec 2022 18:54:52 +0800 Subject: vim-patch:9.0.1097: tests are failing Problem: Tests are failing. Solution: Do clean up a hashtab when at the initial size. https://github.com/vim/vim/commit/b3d614369fceb891819badc941f80f08f57831f9 Co-authored-by: Bram Moolenaar --- src/nvim/hashtab.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 448e78ab07..55198d8e05 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -334,12 +334,13 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) assert(newsize != 0); } - // bail out if the hashtab is already at the desired size - if (newsize == ht->ht_mask + 1) { + 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 return; } - bool newarray_is_small = newsize == HT_INIT_SIZE; bool keep_smallarray = newarray_is_small && ht->ht_array == ht->ht_smallarray; -- cgit From 45d9735aae9aea91420c849aace76ab72e9d3f2a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 27 Dec 2022 18:58:24 +0800 Subject: 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. https://github.com/vim/vim/commit/d0883faac6a74f777c9a6be9d035c59ee1c969c5 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. https://github.com/vim/vim/commit/81b7ecc5cb78cad901a9a85e46ecba109cc6ee7d Co-authored-by: Bram Moolenaar --- src/nvim/hashtab.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 55198d8e05..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; } @@ -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; } -- cgit From 3269902a13df3bccf8705db73488c0a47f495514 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 15 Jan 2023 14:16:33 +0100 Subject: refactor: fix IWYU mapping file and use IWYU (#21802) Also add the EXITFREE definition to main_lib rather than the nvim target, as the header generation needs the EXITFREE flag to work properly. --- src/nvim/hashtab.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 042cb43ce4..f805d99d4b 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -30,6 +30,7 @@ #include "nvim/hashtab.h" #include "nvim/memory.h" #include "nvim/message.h" +#include "nvim/types.h" #include "nvim/vim.h" // Magic value for algorithm that walks through the array. -- cgit From 8a4285d5637c146a0ae606918a8e77063c6a5f0d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 18 Jan 2023 14:17:11 +0100 Subject: refactor: replace char_u with char 24 (#21823) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/hashtab.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/hashtab.c') diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index f805d99d4b..851e70caca 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -88,7 +88,7 @@ void hash_clear_all(hashtab_T *ht, unsigned int off) /// is changed in any way. hashitem_T *hash_find(const hashtab_T *const ht, const char *const key) { - return hash_lookup(ht, key, strlen(key), hash_hash((char_u *)key)); + return hash_lookup(ht, key, strlen(key), hash_hash(key)); } /// Like hash_find, but key is not NUL-terminated @@ -204,13 +204,13 @@ void hash_debug_results(void) /// FAIL if key already present int hash_add(hashtab_T *ht, char *key) { - hash_T hash = hash_hash((char_u *)key); + hash_T hash = hash_hash(key); hashitem_T *hi = hash_lookup(ht, key, strlen(key), hash); if (!HASHITEM_EMPTY(hi)) { internal_error("hash_add()"); return FAIL; } - hash_add_item(ht, hi, (char_u *)key, hash); + hash_add_item(ht, hi, key, hash); return OK; } @@ -221,14 +221,14 @@ int hash_add(hashtab_T *ht, char *key) /// @param key Pointer to the key for the new item. The key has to be contained /// in the new item (@see hashitem_T). Must not be NULL. /// @param hash The precomputed hash value for the key. -void hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash) +void hash_add_item(hashtab_T *ht, hashitem_T *hi, char *key, hash_T hash) { ht->ht_used++; ht->ht_changed++; if (hi->hi_key == NULL) { ht->ht_filled++; } - hi->hi_key = (char *)key; + hi->hi_key = key; hi->hi_hash = hash; // When the space gets low may resize the array. @@ -406,9 +406,9 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) /// run a script that uses hashtables a lot. Vim will then print statistics /// when exiting. Try that with the current hash algorithm and yours. The /// lower the percentage the better. -hash_T hash_hash(const char_u *key) +hash_T hash_hash(const char *key) { - hash_T hash = *key; + hash_T hash = (uint8_t)(*key); if (hash == 0) { return (hash_T)0; @@ -416,7 +416,7 @@ hash_T hash_hash(const char_u *key) // A simplistic algorithm that appears to do very well. // Suggested by George Reilly. - const uint8_t *p = key + 1; + const uint8_t *p = (uint8_t *)key + 1; while (*p != NUL) { HASH_CYCLE_BODY(hash, p); } -- cgit