src/list.c

changeset 528
4fbfac557df8
parent 526
b070ef465313
child 618
1f5a8f6f3015
--- a/src/list.c	Mon Apr 18 16:56:29 2022 +0200
+++ b/src/list.c	Mon Apr 18 17:26:21 2022 +0200
@@ -28,14 +28,26 @@
 
 #include "cx/list.h"
 
-CxList *cxListDestroy(CxList *list) {
-    if (list->content_destructor != NULL) {
-        CxIterator iter = cxListBegin(list);
-        cx_foreach(void*, elem, iter) {
-            list->content_destructor(elem);
+void cxListDestroy(CxList *list) {
+    switch (list->content_destructor_type) {
+        case CX_DESTRUCTOR_SIMPLE: {
+            CxIterator iter = cxListBegin(list);
+            cx_foreach(void*, elem, iter) {
+                list->simple_destructor(elem);
+            }
+            break;
         }
+        case CX_DESTRUCTOR_ADVANCED: {
+            CxIterator iter = cxListBegin(list);
+            cx_foreach(void*, elem, iter) {
+                list->advanced_destructor.func(list->advanced_destructor.data, elem);
+            }
+            break;
+        }
+        case CX_DESTRUCTOR_NONE:
+            break; // nothing
     }
+
     list->cl->destructor(list);
     cxFree(list->allocator, list);
-    return NULL;
 }

mercurial