[Mesa-dev] [PATCH v3 03/63] mesa/util: add new util_dynarray_delete_unordered helper
Nicolai Hähnle
nhaehnle at gmail.com
Mon Jun 12 10:44:35 UTC 2017
On 09.06.2017 15:35, Samuel Pitoiset wrote:
> These helpers will be used for handling dynamic arrays of resident
> texture/image handles.
>
> v3: - replace util_dynarray_delete() by util_dynarray_delete_unordered()
> - remove unused util_dynarray_shrink()
>
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
> Reviewed-by: Marek Olšák <marek.olsak at amd.com> (v2)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
> ---
> src/util/u_dynarray.h | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h
> index e9109ccd2d..70363a074b 100644
> --- a/src/util/u_dynarray.h
> +++ b/src/util/u_dynarray.h
> @@ -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
>
--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
More information about the mesa-dev
mailing list