util/dynarray: add a clone function
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Mon, 13 Aug 2018 21:41:19 +0000 (14:41 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 22 Aug 2018 21:41:26 +0000 (14:41 -0700)
v2: Fix mem_ctx parameter type. (Thomas)

Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/util/u_dynarray.h

index dcbbc06d16122e820b6248de7abc7c2aa56d0986..6bea481d44bfe591a9902b7a8b2fd93c93ca2616 100644 (file)
@@ -102,6 +102,15 @@ util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
    return p;
 }
 
+static inline void
+util_dynarray_clone(struct util_dynarray *buf, void *mem_ctx,
+                    struct util_dynarray *from_buf)
+{
+   util_dynarray_init(buf, mem_ctx);
+   util_dynarray_resize(buf, from_buf->size);
+   memcpy(buf->data, from_buf->data, from_buf->size);
+}
+
 static inline void *
 util_dynarray_grow(struct util_dynarray *buf, int diff)
 {