[Mesa-dev] [PATCH 01/11] util: Add foreach_reverse for dynarray
Caio Marcelo de Oliveira Filho
caio.oliveira at intel.com
Sat Sep 15 05:45:23 UTC 2018
Useful to walk the array removing elements by swapping them with the
last element.
---
src/util/u_dynarray.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h
index 6bea481d44b..f74bfc7080b 100644
--- a/src/util/u_dynarray.h
+++ b/src/util/u_dynarray.h
@@ -154,6 +154,12 @@ util_dynarray_trim(struct util_dynarray *buf)
for (type *elem = (type *)(buf)->data; \
elem < (type *)((char *)(buf)->data + (buf)->size); elem++)
+#define util_dynarray_foreach_reverse(buf, type, elem) \
+ if ((buf)->size > 0) \
+ for (type *elem = util_dynarray_top_ptr(buf, type); \
+ elem >= (type *)(buf)->data; \
+ elem--)
+
#define util_dynarray_delete_unordered(buf, type, v) \
do { \
unsigned num_elements = (buf)->size / sizeof(type); \
--
2.19.0
More information about the mesa-dev
mailing list