From b67fdcdfbc01a04b18dc74f24437b2ffd19f06a5 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 15 Sep 2022 18:31:06 -0500 Subject: [PATCH] util/dynarray: Add an append_array helper Reviewed-by: Caio Oliveira Part-of: --- src/util/u_dynarray.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h index 6f91b820892..b41b0d4b032 100644 --- a/src/util/u_dynarray.h +++ b/src/util/u_dynarray.h @@ -168,6 +168,16 @@ util_dynarray_trim(struct util_dynarray *buf) } } +static inline void +util_dynarray_append_dynarray(struct util_dynarray *buf, + const struct util_dynarray *other) +{ + if (other->size > 0) { + void *p = util_dynarray_grow_bytes(buf, 1, other->size); + memcpy(p, other->data, other->size); + } +} + #define util_dynarray_append(buf, type, v) do {type __v = (v); memcpy(util_dynarray_grow_bytes((buf), 1, sizeof(type)), &__v, sizeof(type));} while(0) /* Returns a pointer to the space of the first new element (in case of growth) or NULL on failure. */ #define util_dynarray_resize(buf, type, nelts) util_dynarray_resize_bytes(buf, (nelts), sizeof(type))