Mon, 18 Apr 2022 15:59:09 +0200
simplify auto-free contents in lists
src/cx/list.h | file | annotate | diff | comparison | revisions | |
src/list.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/cx/list.h Mon Apr 18 15:29:52 2022 +0200 1.2 +++ b/src/cx/list.h Mon Apr 18 15:59:09 2022 +0200 1.3 @@ -90,11 +90,6 @@ 1.4 * The capacity of the list (maximum number of elements). 1.5 */ 1.6 size_t capacity; 1.7 - /** 1.8 - * Flag indicating whether cxListDestroy() shall free each list element, 1.9 - * even if cx_list_s.content_destructor did not do that. 1.10 - */ 1.11 - bool autofree_contents; 1.12 }; 1.13 1.14 /**
2.1 --- a/src/list.c Mon Apr 18 15:29:52 2022 +0200 2.2 +++ b/src/list.c Mon Apr 18 15:59:09 2022 +0200 2.3 @@ -29,25 +29,10 @@ 2.4 #include "cx/list.h" 2.5 2.6 CxList *cxListDestroy(CxList *list) { 2.7 - if (list->content_destructor == NULL) { 2.8 - if (list->autofree_contents) { 2.9 - CxIterator iter = cxListBegin(list); 2.10 - cx_foreach(void*, elem, iter) { 2.11 - cxFree(list->allocator, elem); 2.12 - } 2.13 - } 2.14 - } else { 2.15 - // avoid checking this condition every loop iteration 2.16 - if (list->autofree_contents) { 2.17 - CxIterator iter = cxListBegin(list); 2.18 - cx_foreach(void*, elem, iter) { 2.19 - cxFree(list->allocator, list->content_destructor(elem)); 2.20 - } 2.21 - } else { 2.22 - CxIterator iter = cxListBegin(list); 2.23 - cx_foreach(void*, elem, iter) { 2.24 - elem = list->content_destructor(elem); 2.25 - } 2.26 + if (list->content_destructor != NULL) { 2.27 + CxIterator iter = cxListBegin(list); 2.28 + cx_foreach(void*, elem, iter) { 2.29 + cxFree(list->allocator, list->content_destructor(elem)); 2.30 } 2.31 } 2.32 list->cl->destructor(list);