ecmp_id_slot_get() and ecmp_hash_count_get() use the key itself as the hmap hash. hmap_next_with_hash__() already compares the full hash of each node, not only its bucket, so any node that HMAP_FOR_EACH_WITH_HASH returns already has the key being looked up, and comparing it again is redundant. Use hmap_first_with_hash() instead and drop the now unused 'hash' field of struct ecmp_hash_count.
No functional change. Suggested-by: Rosemarie O'Riorden <[email protected]> Assisted-by: Claude Opus 5.5, Claude Code Signed-off-by: Lucas Vargas Dias <[email protected]> --- northd/en-group-ecmp-route.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/northd/en-group-ecmp-route.c b/northd/en-group-ecmp-route.c index 6992d7c0f..01cca2612 100644 --- a/northd/en-group-ecmp-route.c +++ b/northd/en-group-ecmp-route.c @@ -308,7 +308,7 @@ ecmp_member_hash(const struct parsed_route *route) #define ECMP_ID_MAX_ROUNDS 32 struct ecmp_id_slot { - struct hmap_node hmap_node; + struct hmap_node hmap_node; /* In 'slots', hashed by 'id'. */ uint16_t id; bool taken; /* Assigned to an element. */ size_t n_claims; /* Elements that derived 'id' in the current round. */ @@ -317,35 +317,34 @@ struct ecmp_id_slot { static struct ecmp_id_slot * ecmp_id_slot_get(struct hmap *slots, uint16_t id) { - struct ecmp_id_slot *slot; - HMAP_FOR_EACH_WITH_HASH (slot, hmap_node, id, slots) { - if (slot->id == id) { - return slot; - } + /* The id is the hash itself, so any node with that hash is its slot. */ + struct hmap_node *node = hmap_first_with_hash(slots, id); + if (node) { + return CONTAINER_OF(node, struct ecmp_id_slot, hmap_node); } - slot = xzalloc(sizeof *slot); + + struct ecmp_id_slot *slot = xzalloc(sizeof *slot); slot->id = id; hmap_insert(slots, &slot->hmap_node, id); return slot; } struct ecmp_hash_count { - struct hmap_node hmap_node; - uint32_t hash; + struct hmap_node hmap_node; /* In 'counts', hashed by the counted hash. */ size_t n; }; static struct ecmp_hash_count * ecmp_hash_count_get(struct hmap *counts, uint32_t hash) { - struct ecmp_hash_count *count; - HMAP_FOR_EACH_WITH_HASH (count, hmap_node, hash, counts) { - if (count->hash == hash) { - return count; - } + /* The counted hash is used as the hmap hash, so any node with that hash + * is its count. */ + struct hmap_node *node = hmap_first_with_hash(counts, hash); + if (node) { + return CONTAINER_OF(node, struct ecmp_hash_count, hmap_node); } - count = xzalloc(sizeof *count); - count->hash = hash; + + struct ecmp_hash_count *count = xzalloc(sizeof *count); hmap_insert(counts, &count->hmap_node, hash); return count; } -- 2.43.0 -- _'Esta mensagem é direcionada apenas para os endereços constantes no cabeçalho inicial. Se você não está listado nos endereços constantes no cabeçalho, pedimos-lhe que desconsidere completamente o conteúdo dessa mensagem e cuja cópia, encaminhamento e/ou execução das ações citadas estão imediatamente anuladas e proibidas'._ * **'Apesar do Magazine Luiza tomar todas as precauções razoáveis para assegurar que nenhum vírus esteja presente nesse e-mail, a empresa não poderá aceitar a responsabilidade por quaisquer perdas ou danos causados por esse e-mail ou por seus anexos'.* _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
