summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdrian Moreno <amorenoz@redhat.com>2022-03-23 12:56:14 +0100
committerIlya Maximets <i.maximets@ovn.org>2022-03-30 16:59:02 +0200
commite9bf5bffb020e3dca4104118e15c69242bc12e33 (patch)
tree01e35216faf311d3313c6f20464dc884c2dc1f81 /include
parentd4566085edf50033087652f35f92b9b77cbec70f (diff)
downloadopenvswitch-e9bf5bffb020e3dca4104118e15c69242bc12e33.tar.gz
list: use short version of safe loops if possible.
Using the 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. 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>
Diffstat (limited to 'include')
-rw-r--r--include/openvswitch/list.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/include/openvswitch/list.h b/include/openvswitch/list.h
index bbd2edbd0..6272d340c 100644
--- a/include/openvswitch/list.h
+++ b/include/openvswitch/list.h
@@ -92,7 +92,8 @@ static inline bool ovs_list_is_short(const struct ovs_list *);
CONDITION_MULTIVAR(VAR, MEMBER, ITER_VAR(VAR) != (LIST)); \
UPDATE_MULTIVAR(VAR, ITER_VAR(VAR)->prev))
-#define LIST_FOR_EACH_REVERSE_SAFE(VAR, PREV, MEMBER, LIST) \
+/* LONG version of SAFE iterators. */
+#define LIST_FOR_EACH_REVERSE_SAFE_LONG(VAR, PREV, MEMBER, LIST) \
for (INIT_MULTIVAR_SAFE_LONG(VAR, PREV, MEMBER, (LIST)->prev, \
struct ovs_list); \
CONDITION_MULTIVAR_SAFE_LONG(VAR, PREV, MEMBER, \
@@ -101,7 +102,7 @@ static inline bool ovs_list_is_short(const struct ovs_list *);
ITER_VAR(PREV) != (LIST)); \
UPDATE_MULTIVAR_SAFE_LONG(VAR, PREV))
-#define LIST_FOR_EACH_SAFE(VAR, NEXT, MEMBER, LIST) \
+#define LIST_FOR_EACH_SAFE_LONG(VAR, NEXT, MEMBER, LIST) \
for (INIT_MULTIVAR_SAFE_LONG(VAR, NEXT, MEMBER, (LIST)->next, \
struct ovs_list); \
CONDITION_MULTIVAR_SAFE_LONG(VAR, NEXT, MEMBER, \
@@ -110,6 +111,31 @@ static inline bool ovs_list_is_short(const struct ovs_list *);
ITER_VAR(NEXT) != (LIST)); \
UPDATE_MULTIVAR_SAFE_LONG(VAR, NEXT))
+/* SHORT version of SAFE iterators. */
+#define LIST_FOR_EACH_REVERSE_SAFE_SHORT(VAR, MEMBER, LIST) \
+ for (INIT_MULTIVAR_SAFE_SHORT(VAR, MEMBER, (LIST)->prev, struct ovs_list);\
+ CONDITION_MULTIVAR_SAFE_SHORT(VAR, MEMBER, \
+ ITER_VAR(VAR) != (LIST), \
+ ITER_NEXT_VAR(VAR) = ITER_VAR(VAR)->prev); \
+ UPDATE_MULTIVAR_SAFE_SHORT(VAR))
+
+#define LIST_FOR_EACH_SAFE_SHORT(VAR, MEMBER, LIST) \
+ for (INIT_MULTIVAR_SAFE_SHORT(VAR, MEMBER, (LIST)->next, struct ovs_list);\
+ CONDITION_MULTIVAR_SAFE_SHORT(VAR, MEMBER, \
+ ITER_VAR(VAR) != (LIST), \
+ ITER_NEXT_VAR(VAR) = ITER_VAR(VAR)->next); \
+ UPDATE_MULTIVAR_SAFE_SHORT(VAR))
+
+#define LIST_FOR_EACH_SAFE(...) \
+ OVERLOAD_SAFE_MACRO(LIST_FOR_EACH_SAFE_LONG, \
+ LIST_FOR_EACH_SAFE_SHORT, \
+ 4, __VA_ARGS__)
+
+#define LIST_FOR_EACH_REVERSE_SAFE(...) \
+ OVERLOAD_SAFE_MACRO(LIST_FOR_EACH_REVERSE_SAFE_LONG, \
+ LIST_FOR_EACH_REVERSE_SAFE_SHORT, \
+ 4, __VA_ARGS__)
+
#define LIST_FOR_EACH_POP(ITER, MEMBER, LIST) \
while (!ovs_list_is_empty(LIST) ? \
(INIT_CONTAINER(ITER, ovs_list_pop_front(LIST), MEMBER), 1) : \