|
15 | 15 | static inline size_t hash_bits(size_t h, int bits)
|
16 | 16 | {
|
17 | 17 | /* shuffle bits and return requested number of upper bits */
|
| 18 | + if (bits == 0) |
| 19 | + return 0; |
| 20 | + |
18 | 21 | #if (__SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__)
|
19 | 22 | /* LP64 case */
|
20 | 23 | return (h * 11400714819323198485llu) >> (__SIZEOF_LONG_LONG__ * 8 - bits);
|
@@ -174,17 +177,17 @@ bool hashmap__find(const struct hashmap *map, const void *key, void **value);
|
174 | 177 | * @key: key to iterate entries for
|
175 | 178 | */
|
176 | 179 | #define hashmap__for_each_key_entry(map, cur, _key) \
|
177 |
| - for (cur = ({ size_t bkt = hash_bits(map->hash_fn((_key), map->ctx),\ |
178 |
| - map->cap_bits); \ |
179 |
| - map->buckets ? map->buckets[bkt] : NULL; }); \ |
| 180 | + for (cur = map->buckets \ |
| 181 | + ? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \ |
| 182 | + : NULL; \ |
180 | 183 | cur; \
|
181 | 184 | cur = cur->next) \
|
182 | 185 | if (map->equal_fn(cur->key, (_key), map->ctx))
|
183 | 186 |
|
184 | 187 | #define hashmap__for_each_key_entry_safe(map, cur, tmp, _key) \
|
185 |
| - for (cur = ({ size_t bkt = hash_bits(map->hash_fn((_key), map->ctx),\ |
186 |
| - map->cap_bits); \ |
187 |
| - cur = map->buckets ? map->buckets[bkt] : NULL; }); \ |
| 188 | + for (cur = map->buckets \ |
| 189 | + ? map->buckets[hash_bits(map->hash_fn((_key), map->ctx), map->cap_bits)] \ |
| 190 | + : NULL; \ |
188 | 191 | cur && ({ tmp = cur->next; true; }); \
|
189 | 192 | cur = tmp) \
|
190 | 193 | if (map->equal_fn(cur->key, (_key), map->ctx))
|
|
0 commit comments