2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

lib: Use MAP_FOR_EACH_INDEX to improve readability.

Use MAP_FOR_EACH_INDEX to improve readability when there is no
apparent cost for it.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Jarno Rajahalme
2014-11-26 15:30:33 -08:00
parent f4d335e985
commit 1cea007c92
5 changed files with 34 additions and 42 deletions

View File

@@ -132,11 +132,11 @@ flow_hash_in_minimask(const struct flow *flow, const struct minimask *mask,
const uint32_t *flow_u32 = (const uint32_t *)flow;
const uint32_t *p = mask_values;
uint32_t hash;
uint64_t map;
int idx;
hash = basis;
for (map = mask->masks.map; map; map = zero_rightmost_1bit(map)) {
hash = hash_add(hash, flow_u32[raw_ctz(map)] & *p++);
MAP_FOR_EACH_INDEX(idx, mask->masks.map) {
hash = hash_add(hash, flow_u32[idx] & *p++);
}
return hash_finish(hash, (p - mask_values) * 4);
@@ -180,9 +180,10 @@ flow_hash_in_minimask_range(const struct flow *flow,
&offset);
const uint32_t *p = mask_values + offset;
uint32_t hash = *basis;
int idx;
for (; map; map = zero_rightmost_1bit(map)) {
hash = hash_add(hash, flow_u32[raw_ctz(map)] & *p++);
MAP_FOR_EACH_INDEX(idx, map) {
hash = hash_add(hash, flow_u32[idx] & *p++);
}
*basis = hash; /* Allow continuation from the unfinished value. */
@@ -209,9 +210,10 @@ flow_wildcards_fold_minimask_range(struct flow_wildcards *wc,
uint64_t map = miniflow_get_map_in_range(&mask->masks, start, end,
&offset);
const uint32_t *p = miniflow_get_u32_values(&mask->masks) + offset;
int idx;
for (; map; map = zero_rightmost_1bit(map)) {
dst_u32[raw_ctz(map)] |= *p++;
MAP_FOR_EACH_INDEX(idx, map) {
dst_u32[idx] |= *p++;
}
}