On Thu, Jun 8, 2017 at 12:26 PM, Samuel Pitoiset <samuel.pitoi...@gmail.com> wrote: > > > On 06/07/2017 06:21 PM, Nicolai Hähnle wrote: >> >> 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. > > > It doesn't matter, at least not for bindless handles. > >> >> Might be wise to rename the macro to util_dynarray_delete_unordered to >> avoid future confusion.
I think Nicolai meant that the "util_dynarray_delete_unordered" name be used for the case when it copies the last element to the gap. Marek _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev