diff options
author | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-05-24 01:17:47 +0200 |
---|---|---|
committer | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-05-24 01:17:47 +0200 |
commit | ec89761e8a05fb93ed6bbde1055fbc866f7bce7e (patch) | |
tree | b2efee00f796761bb7362489ea4ba3d17f378720 | |
parent | 0c68623aca08fa84c7ed945bac7d5066de84d7f7 (diff) | |
download | rneovim-ec89761e8a05fb93ed6bbde1055fbc866f7bce7e.tar.gz rneovim-ec89761e8a05fb93ed6bbde1055fbc866f7bce7e.tar.bz2 rneovim-ec89761e8a05fb93ed6bbde1055fbc866f7bce7e.zip |
Remove long_u: hashtab: Refactor long_u type.
hashtab.h:
- hash_T: long_u -> size_t.
In principle, a hash value could thought of as just an unsigned number
without size semantics (uint32_t or uint64_t). But it is used as
index at some places, and so, size_t is also eligible. Therea re some
places where assignments occur between hash_T and size_t variables, in
both directions. Therefore, if we define hash_T to be of a type having
a different width than that of size_t, we will have an incorrect
assignment somewhere that will require an assert/guard. So the most
sensible option here seems to do hast_T to be size_t too.
- hashtab_T.ht_mask: long_u -> hash_T.
Masks are used to be combined with hash_T values, so they should be of
the same type.
hashtab.c:
- hash_may_resize(): oldsize: long_u -> size_t.
- hash_may_resize(): newsize: long_u -> size_t.
- hash_may_resize(): newmask: long_u -> hash_T.
-rw-r--r-- | src/nvim/hashtab.c | 8 | ||||
-rw-r--r-- | src/nvim/hashtab.h | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 664c4eaf92..3f5e4cf4a1 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -281,7 +281,7 @@ static int 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) - long_u oldsize = ht->ht_mask + 1; + size_t oldsize = ht->ht_mask + 1; if ((ht->ht_filled * 3 < oldsize * 2) && (ht->ht_used > oldsize / 5)) { return OK; } @@ -303,7 +303,7 @@ static int hash_may_resize(hashtab_T *ht, size_t minitems) minsize = minitems * 3 / 2; } - long_u newsize = HT_INIT_SIZE; + size_t newsize = HT_INIT_SIZE; while (newsize < minsize) { // make sure it's always a power of 2 newsize <<= 1; @@ -327,12 +327,12 @@ static int hash_may_resize(hashtab_T *ht, size_t minitems) ? ht->ht_smallarray : xmalloc(sizeof(hashitem_T) * newsize); - memset(newarray, 0, (size_t)(sizeof(hashitem_T) * newsize)); + memset(newarray, 0, sizeof(hashitem_T) * newsize); // Move all the items from the old array to the new one, placing them in // the right spot. The new array won't have any removed items, thus this // is also a cleanup action. - long_u newmask = newsize - 1; + hash_T newmask = newsize - 1; int todo = (int)ht->ht_used; for (hashitem_T *olditem = oldarray; todo > 0; ++olditem) { diff --git a/src/nvim/hashtab.h b/src/nvim/hashtab.h index b556c6a9f3..8fba1c1ef5 100644 --- a/src/nvim/hashtab.h +++ b/src/nvim/hashtab.h @@ -4,7 +4,7 @@ #include "nvim/vim.h" /// Type for hash number (hash calculation result). -typedef long_u hash_T; +typedef size_t hash_T; /// The address of "hash_removed" is used as a magic number /// for hi_key to indicate a removed item. @@ -53,10 +53,10 @@ typedef struct hashitem_S { /// /// The hashtable grows to accommodate more entries when needed. typedef struct hashtable_S { - long_u ht_mask; /// mask used for hash value + hash_T ht_mask; /// mask used for hash value /// (nr of items in array is "ht_mask" + 1) - long_u ht_used; /// number of items used - long_u ht_filled; /// number of items used or removed + size_t ht_used; /// number of items used + size_t ht_filled; /// number of items used or removed int ht_locked; /// counter for hash_lock() int ht_error; /// when set growing failed, can't add more /// items before growing works |