util/dynarray: Add an append_array helper

Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19685>
This commit is contained in:
Jason Ekstrand 2022-09-15 18:31:06 -05:00 committed by Marge Bot
parent db0e6f9a07
commit b67fdcdfbc

View file

@ -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))