Mercurial > vim
diff src/hashtab.c @ 20007:aadd1cae2ff5 v8.2.0559
patch 8.2.0559: clearing a struct is verbose
Commit: https://github.com/vim/vim/commit/a80faa8930ed5a554beeb2727762538873135e83
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 12 19:37:17 2020 +0200
patch 8.2.0559: clearing a struct is verbose
Problem: Clearing a struct is verbose.
Solution: Define and use CLEAR_FIELD() and CLEAR_POINTER().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Apr 2020 19:45:05 +0200 |
parents | f0f9692d4487 |
children | 883aa425656a |
line wrap: on
line diff
--- a/src/hashtab.c +++ b/src/hashtab.c @@ -65,7 +65,7 @@ hash_create(void) hash_init(hashtab_T *ht) { // This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". - vim_memset(ht, 0, sizeof(hashtab_T)); + CLEAR_POINTER(ht); ht->ht_array = ht->ht_smallarray; ht->ht_mask = HT_INIT_SIZE - 1; } @@ -394,11 +394,12 @@ hash_may_resize( } else oldarray = ht->ht_array; + CLEAR_FIELD(ht->ht_smallarray); } else { // Allocate an array. - newarray = ALLOC_MULT(hashitem_T, newsize); + newarray = ALLOC_CLEAR_MULT(hashitem_T, newsize); if (newarray == NULL) { // Out of memory. When there are NULL items still return OK. @@ -411,7 +412,6 @@ hash_may_resize( } oldarray = ht->ht_array; } - vim_memset(newarray, 0, (size_t)(sizeof(hashitem_T) * newsize)); /* * Move all the items from the old array to the new one, placing them in