Mesa (master): util: Add foreach_reverse for dynarray

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 16 00:35:04 UTC 2018


Module: Mesa
Branch: master
Commit: 3966f053a14c5f1c57738143fea3d239070e5517
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3966f053a14c5f1c57738143fea3d239070e5517

Author: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Date:   Wed Sep 12 14:57:35 2018 -0700

util: Add foreach_reverse for dynarray

Useful to walk the array removing elements by swapping them with the
last element.

v2: Change iteration to make sure we never underflow. (Jason)

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

---

 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 512c0efc76..c1aa79c8ac 100644
--- a/src/util/u_dynarray.h
+++ b/src/util/u_dynarray.h
@@ -155,6 +155,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;                                                \
+           elem = elem > (type *)(buf)->data ? elem - 1 : NULL)
+
 #define util_dynarray_delete_unordered(buf, type, v)                    \
    do {                                                                 \
       unsigned num_elements = (buf)->size / sizeof(type);               \




More information about the mesa-commit mailing list