From db23cb05d1d40487007b3c93dd54fab290fd02b7 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Sat, 19 Apr 2014 13:12:04 -0300 Subject: Use /2 and 2* instead of >>1 and <<1 which are tricky with signed types Today's compilers generate shift instructions to perform division and multiplications by powers of 2 [1]. `(x >> 1)` looks straightforward enough, but if x is signed the code will fail when x < 0. The compiler knows better: use `x / 2`. That's why we have code like this: (long)((long_u)Rows >> 1)) instead of the cleaner version that generates the same or better machine code: Rows / 2 [1] http://goo.gl/J4WpG7 --- src/hashtab.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/hashtab.c') diff --git a/src/hashtab.c b/src/hashtab.c index b84b56278f..a43180d6cb 100644 --- a/src/hashtab.c +++ b/src/hashtab.c @@ -141,7 +141,7 @@ hashitem_T* hash_lookup(hashtab_T *ht, char_u *key, hash_T hash) // count a "miss" for hashtab lookup hash_count_perturb++; #endif // ifdef HT_DEBUG - idx = (unsigned)((idx << 2U) + idx + perturb + 1U); + idx = 5 * idx + perturb + 1; hi = &ht->ht_array[idx & ht->ht_mask]; if (hi->hi_key == NULL) { @@ -378,7 +378,7 @@ static int hash_may_resize(hashtab_T *ht, int minitems) newitem = &newarray[newi]; if (newitem->hi_key != NULL) { for (perturb = olditem->hi_hash;; perturb >>= PERTURB_SHIFT) { - newi = (unsigned)((newi << 2U) + newi + perturb + 1U); + newi = 5 * newi + perturb + 1; newitem = &newarray[newi & newmask]; if (newitem->hi_key == NULL) { break; -- cgit