diff -r d0680a23d850 -r b09aae58bba4 src/linked_list.c --- a/src/linked_list.c Fri Apr 07 11:30:28 2023 +0200 +++ b/src/linked_list.c Sun Apr 09 19:03:58 2023 +0200 @@ -60,7 +60,7 @@ void const *start, ptrdiff_t loc_advance, ptrdiff_t loc_data, - CxListComparator cmp_func, + cx_compare_func cmp_func, void const *elem ) { assert(start != NULL); @@ -291,7 +291,7 @@ void *ls, void *le, void *re, - CxListComparator cmp_func + cx_compare_func cmp_func ) { void *sbo[CX_LINKED_LIST_SORT_SBO_SIZE]; void **sorted = length >= CX_LINKED_LIST_SORT_SBO_SIZE ? @@ -343,7 +343,7 @@ ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, - CxListComparator cmp_func + cx_compare_func cmp_func ) { assert(begin != NULL); assert(loc_next >= 0); @@ -403,7 +403,7 @@ void const *begin_right, ptrdiff_t loc_advance, ptrdiff_t loc_data, - CxListComparator cmp_func + cx_compare_func cmp_func ) { void const *left = begin_left, *right = begin_right; @@ -494,14 +494,14 @@ // create the new new_node cx_linked_list_node *new_node = cxMalloc(list->allocator, - sizeof(cx_linked_list_node) + list->itemsize); + sizeof(cx_linked_list_node) + list->item_size); // sortir if failed if (new_node == NULL) return 1; // initialize new new_node new_node->prev = new_node->next = NULL; - memcpy(new_node->payload, elem, list->itemsize); + memcpy(new_node->payload, elem, list->item_size); // insert cx_linked_list *ll = (cx_linked_list *) list; @@ -542,7 +542,7 @@ // we can add the remaining nodes and immedately advance to the inserted node char const *source = array; for (size_t i = 1; i < n; i++) { - source += list->itemsize; + source += list->item_size; if (0 != cx_ll_insert_at(list, node, source)) { return i; } @@ -570,9 +570,7 @@ if (node == NULL) return 1; // element destruction - if (list->content_destructor_type != CX_DESTRUCTOR_NONE) { - cx_list_invoke_destructor(list, node->payload); - } + cx_invoke_destructor(list, node->payload); // remove cx_linked_list_remove((void **) &ll->begin, (void **) &ll->end, @@ -592,38 +590,12 @@ cx_linked_list *ll = (cx_linked_list *) list; cx_linked_list_node *node = ll->begin; - - // looks super redundant, but avoids repeatedly checking - // the destructor type for each element - switch (list->content_destructor_type) { - case CX_DESTRUCTOR_SIMPLE: { - while (node != NULL) { - cx_list_invoke_simple_destructor(list, node->payload); - cx_linked_list_node *next = node->next; - cxFree(list->allocator, node); - node = next; - } - break; - } - case CX_DESTRUCTOR_ADVANCED: { - while (node != NULL) { - cx_list_invoke_advanced_destructor(list, node->payload); - cx_linked_list_node *next = node->next; - cxFree(list->allocator, node); - node = next; - } - break; - } - case CX_DESTRUCTOR_NONE: { - while (node != NULL) { - cx_linked_list_node *next = node->next; - cxFree(list->allocator, node); - node = next; - } - break; - } + while (node != NULL) { + cx_invoke_destructor(list, node->payload); + cx_linked_list_node *next = node->next; + cxFree(list->allocator, node); + node = next; } - ll->begin = ll->end = NULL; list->size = 0; } @@ -708,7 +680,7 @@ } } - if (list->itemsize > CX_LINKED_LIST_SWAP_SBO_SIZE || CX_DISABLE_LINKED_LIST_SWAP_SBO) { + if (list->item_size > CX_LINKED_LIST_SWAP_SBO_SIZE || CX_DISABLE_LINKED_LIST_SWAP_SBO) { cx_linked_list_node *prev = nleft->prev; cx_linked_list_node *next = nright->next; cx_linked_list_node *midstart = nleft->next; @@ -740,9 +712,9 @@ } else { // swap payloads to avoid relinking char buf[CX_LINKED_LIST_SWAP_SBO_SIZE]; - memcpy(buf, nleft->payload, list->itemsize); - memcpy(nleft->payload, nright->payload, list->itemsize); - memcpy(nright->payload, buf, list->itemsize); + memcpy(buf, nleft->payload, list->item_size); + memcpy(nleft->payload, nright->payload, list->item_size); + memcpy(nright->payload, buf, list->item_size); } return 0; @@ -803,9 +775,7 @@ cx_linked_list *ll = iter->src_handle; cx_linked_list_node *node = iter->elem_handle; iter->elem_handle = node->next; - if (list->content_destructor_type != CX_DESTRUCTOR_NONE) { - cx_list_invoke_destructor(list, node->payload); - } + cx_invoke_destructor(list, node->payload); cx_linked_list_remove((void **) &ll->begin, (void **) &ll->end, CX_LL_LOC_PREV, CX_LL_LOC_NEXT, node); list->size--; @@ -828,9 +798,7 @@ cx_linked_list_node *node = iter->elem_handle; iter->elem_handle = node->prev; iter->index--; - if (list->content_destructor_type != CX_DESTRUCTOR_NONE) { - cx_list_invoke_destructor(list, node->payload); - } + cx_invoke_destructor(list, node->payload); cx_linked_list_remove((void **) &ll->begin, (void **) &ll->end, CX_LL_LOC_PREV, CX_LL_LOC_NEXT, node); list->size--; @@ -927,7 +895,7 @@ CxList *cxLinkedListCreate( CxAllocator const *allocator, - CxListComparator comparator, + cx_compare_func comparator, size_t item_size ) { if (allocator == NULL) { @@ -940,10 +908,9 @@ list->base.cl = &cx_linked_list_class; list->base.allocator = allocator; list->base.cmpfunc = comparator; - list->base.capacity = SIZE_MAX; if (item_size > 0) { - list->base.itemsize = item_size; + list->base.item_size = item_size; } else { cxListStorePointers((CxList *) list); }