summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>2018-09-12 14:57:35 -0700
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>2018-10-15 17:29:46 -0700
commit3966f053a14c5f1c57738143fea3d239070e5517 (patch)
tree923dd79c34c46b37b7ad9fb4224c17c67e82ff67 /src/util
parent8ec83dc51e407fa0987d636752497509278c0dbb (diff)
downloadmesa-3966f053a14c5f1c57738143fea3d239070e5517.tar.gz
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@jlekstrand.net>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/u_dynarray.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h
index 512c0efc762..c1aa79c8ac6 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); \