From 190ad01eb758f85ae20b945cfc75c7204da88d84 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Sun, 5 Aug 2018 17:26:37 +0200 Subject: [PATCH] Memory: restore CloneList() function which was removed in #608 --- src/Mayaqua/Memory.c | 14 ++++++++++++++ src/Mayaqua/Memory.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/Mayaqua/Memory.c b/src/Mayaqua/Memory.c index e5011c16..3de5c16b 100644 --- a/src/Mayaqua/Memory.c +++ b/src/Mayaqua/Memory.c @@ -1326,6 +1326,20 @@ QUEUE *NewQueueFast() return q; } +// Clone the list +LIST *CloneList(LIST *o) +{ + LIST *n = NewList(o->cmp); + + // Memory reallocation + Free(n->p); + n->p = ToArray(o); + n->num_item = n->num_reserved = LIST_NUM(o); + n->sorted = o->sorted; + + return n; +} + // Copy the list to an array void CopyToArray(LIST *o, void *p) { diff --git a/src/Mayaqua/Memory.h b/src/Mayaqua/Memory.h index 8059efcb..11f9fa2e 100644 --- a/src/Mayaqua/Memory.h +++ b/src/Mayaqua/Memory.h @@ -380,6 +380,7 @@ LIST *NewListFast(COMPARE *cmp); LIST *NewListEx(COMPARE *cmp, bool fast); LIST *NewListEx2(COMPARE *cmp, bool fast, bool fast_malloc); LIST *NewListSingle(void *p); +LIST *CloneList(LIST *o); void CopyToArray(LIST *o, void *p); void *ToArray(LIST *o); void *ToArrayEx(LIST *o, bool fast);