On 30.05.2017 22:35, Samuel Pitoiset wrote:
These helpers will be used for handling dynamic arrays of resident
texture/image handles.

Signed-off-by: Samuel Pitoiset <samuel.pitoi...@gmail.com>
---
  src/gallium/auxiliary/util/u_dynarray.h | 20 ++++++++++++++++++++
  1 file changed, 20 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_dynarray.h 
b/src/gallium/auxiliary/util/u_dynarray.h
index 7b7a093d82..d6f3d5c901 100644
--- a/src/gallium/auxiliary/util/u_dynarray.h
+++ b/src/gallium/auxiliary/util/u_dynarray.h
@@ -109,6 +109,26 @@ util_dynarray_trim(struct util_dynarray *buf)
  #define util_dynarray_element(buf, type, idx) ((type*)(buf)->data + (idx))
  #define util_dynarray_begin(buf) ((buf)->data)
  #define util_dynarray_end(buf) ((void*)util_dynarray_element((buf), char, 
(buf)->size))
+#define util_dynarray_shrink(buf, type, begin, end)                        \
+   do {                                                                    \
+      void *__begin = util_dynarray_element((buf), type, (begin));         \
+      void *__end = util_dynarray_element((buf), type, (end));             \
+      if ((end) * sizeof(type) < (buf)->size)                              \
+         memmove(__begin, __end, (buf)->size - ((end) * sizeof(type)));    \
+      (buf)->size = (buf)->size - ((end) - (begin)) * sizeof(type);        \
+   } while (0)
+#define util_dynarray_delete(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) {                                             \
+            util_dynarray_shrink((buf), type, i, i + 1);             \
+            break;                                                   \
+         }                                                           \
+      }                                                              \
+   } while (0)

Does the order of elements matter? If not, it would be better to just copy the last element into the gap that is left by the deleted element.

Might be wise to rename the macro to util_dynarray_delete_unordered to avoid future confusion.

Cheers,
Nicolai


#endif /* U_DYNARRAY_H */


--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to