summaryrefslogtreecommitdiffstats
path: root/src/util/set.c
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <[email protected]>2018-06-25 09:51:20 -0700
committerRafael Antognolli <[email protected]>2018-07-12 14:03:51 -0700
commitb034facfbc446b28f2cc92c32122849a25fb1001 (patch)
treef999a9ccc39fe025b3d0f442cd542b46e03a7371 /src/util/set.c
parent8af0a45b4701aa99616b6d5975025ce793172a9c (diff)
util/set: add a clone function
v2: Add unit test. (Eric Anholt) Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/util/set.c')
-rw-r--r--src/util/set.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util/set.c b/src/util/set.c
index 2c9b09319ff..b2aa5ba13d5 100644
--- a/src/util/set.c
+++ b/src/util/set.c
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <assert.h>
+#include <string.h>
#include "macros.h"
#include "ralloc.h"
@@ -132,6 +133,28 @@ _mesa_set_create(void *mem_ctx,
return ht;
}
+struct set *
+_mesa_set_clone(struct set *set, void *dst_mem_ctx)
+{
+ struct set *clone;
+
+ clone = ralloc(dst_mem_ctx, struct set);
+ if (clone == NULL)
+ return NULL;
+
+ memcpy(clone, set, sizeof(struct set));
+
+ clone->table = ralloc_array(clone, struct set_entry, clone->size);
+ if (clone->table == NULL) {
+ ralloc_free(clone);
+ return NULL;
+ }
+
+ memcpy(clone->table, set->table, clone->size * sizeof(struct set_entry));
+
+ return clone;
+}
+
/**
* Frees the given set.
*