# HG changeset patch # User Mike Becker # Date 1650290349 -7200 # Node ID 536646d1575b8004bffdd7adbc4d96b199935867 # Parent e98b09018d328487416f7cf7a49965ccc5e04cf4 simplify auto-free contents in lists diff -r e98b09018d32 -r 536646d1575b src/cx/list.h --- a/src/cx/list.h Mon Apr 18 15:29:52 2022 +0200 +++ b/src/cx/list.h Mon Apr 18 15:59:09 2022 +0200 @@ -90,11 +90,6 @@ * The capacity of the list (maximum number of elements). */ size_t capacity; - /** - * Flag indicating whether cxListDestroy() shall free each list element, - * even if cx_list_s.content_destructor did not do that. - */ - bool autofree_contents; }; /** diff -r e98b09018d32 -r 536646d1575b src/list.c --- a/src/list.c Mon Apr 18 15:29:52 2022 +0200 +++ b/src/list.c Mon Apr 18 15:59:09 2022 +0200 @@ -29,25 +29,10 @@ #include "cx/list.h" CxList *cxListDestroy(CxList *list) { - if (list->content_destructor == NULL) { - if (list->autofree_contents) { - CxIterator iter = cxListBegin(list); - cx_foreach(void*, elem, iter) { - cxFree(list->allocator, elem); - } - } - } else { - // avoid checking this condition every loop iteration - if (list->autofree_contents) { - CxIterator iter = cxListBegin(list); - cx_foreach(void*, elem, iter) { - cxFree(list->allocator, list->content_destructor(elem)); - } - } else { - CxIterator iter = cxListBegin(list); - cx_foreach(void*, elem, iter) { - elem = list->content_destructor(elem); - } + if (list->content_destructor != NULL) { + CxIterator iter = cxListBegin(list); + cx_foreach(void*, elem, iter) { + cxFree(list->allocator, list->content_destructor(elem)); } } list->cl->destructor(list);