2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-01 14:55:18 +00:00

hmap: use short version of safe loops if possible.

Using SHORT version of the *_SAFE loops makes the code cleaner and less
error prone. So, use the SHORT version and remove the extra variable
when possible for hmap and all its derived types.

In order to be able to use both long and short versions without changing
the name of the macro for all the clients, overload the existing name
and select the appropriate version depending on the number of arguments.

Acked-by: Dumitru Ceara <dceara@redhat.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Adrian Moreno
2022-03-23 12:56:17 +01:00
committed by Ilya Maximets
parent 860e69a8c3
commit 9e56549c2b
57 changed files with 304 additions and 215 deletions

View File

@@ -41,13 +41,24 @@ struct shash {
BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \
BUILD_ASSERT_TYPE(SHASH, struct shash *))
#define SHASH_FOR_EACH_SAFE(SHASH_NODE, NEXT, SHASH) \
HMAP_FOR_EACH_SAFE_INIT ( \
#define SHASH_FOR_EACH_SAFE_SHORT(SHASH_NODE, SHASH) \
HMAP_FOR_EACH_SAFE_SHORT_INIT ( \
SHASH_NODE, node, &(SHASH)->map, \
BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \
BUILD_ASSERT_TYPE(SHASH, struct shash *))
#define SHASH_FOR_EACH_SAFE_LONG(SHASH_NODE, NEXT, SHASH) \
HMAP_FOR_EACH_SAFE_LONG_INIT ( \
SHASH_NODE, NEXT, node, &(SHASH)->map, \
BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \
BUILD_ASSERT_TYPE(NEXT, struct shash_node *), \
BUILD_ASSERT_TYPE(SHASH, struct shash *))
#define SHASH_FOR_EACH_SAFE(...) \
OVERLOAD_SAFE_MACRO(SHASH_FOR_EACH_SAFE_LONG, \
SHASH_FOR_EACH_SAFE_SHORT, \
3, __VA_ARGS__)
void shash_init(struct shash *);
void shash_destroy(struct shash *);
void shash_destroy_free_data(struct shash *);