mesa/util: add new util_dynarray_delete_unordered helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 29 May 2017 15:26:30 +0000 (17:26 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 14 Jun 2017 08:04:35 +0000 (10:04 +0200)
This helper function will be used for managing dynamic arrays of
resident texture/image handles.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/util/u_dynarray.h

index fdcd09c4befeae7abdcb69c51a19a9caef0b0dda..57f96ff79c0ea7b9b7e1e8e279c2ceee568d822a 100644 (file)
@@ -138,6 +138,20 @@ util_dynarray_trim(struct util_dynarray *buf)
    for (type *elem = (type *)(buf)->data; \
         elem < (type *)((char *)(buf)->data + (buf)->size); elem++)
 
+#define util_dynarray_delete_unordered(buf, type, v)                    \
+   do {                                                                 \
+      unsigned num_elements = (buf)->size / sizeof(type);               \
+      unsigned i;                                                       \
+      for (i = 0; i < num_elements; i++) {                              \
+         type __v = *util_dynarray_element((buf), type, (i));           \
+         if (v == __v) {                                                \
+            memcpy(util_dynarray_element((buf), type, (i)),             \
+                   util_dynarray_pop_ptr((buf), type), sizeof(type));   \
+            break;                                                      \
+         }                                                              \
+      }                                                                 \
+   } while (0)
+
 #ifdef __cplusplus
 }
 #endif