diff -r 1e2be40f0cb5 -r 6c81ee4f11ad src/linked_list.c --- a/src/linked_list.c Sun Nov 20 21:08:36 2022 +0100 +++ b/src/linked_list.c Wed Nov 23 22:40:55 2022 +0100 @@ -540,6 +540,20 @@ return cx_ll_insert(list, list->size, elem); } +static size_t cx_ll_add_array( + struct cx_list_s *list, + void const *array, + size_t n +) { + // TODO: redirect to cx_ll_insert_array + cx_for_n (i, n) { + if (cx_ll_add(list, ((char const *) array) + i * list->itemsize)) { + return i; + } + } + return n; +} + static int cx_pll_insert( struct cx_list_s *list, size_t index, @@ -727,6 +741,7 @@ static cx_list_class cx_linked_list_class = { cx_ll_destructor, cx_ll_add, + cx_ll_add_array, cx_ll_insert, cx_ll_insert_iter, cx_ll_remove, @@ -741,6 +756,7 @@ static cx_list_class cx_pointer_linked_list_class = { cx_ll_destructor, cx_pll_add, + cx_ll_add_array, cx_pll_insert, cx_pll_insert_iter, cx_ll_remove, @@ -786,22 +802,3 @@ return (CxList *) list; } - -CxList *cxLinkedListFromArray( - CxAllocator const *allocator, - CxListComparator comparator, - size_t item_size, - size_t num_items, - void const *array -) { - CxList *list = cxLinkedListCreate(allocator, comparator, item_size); - if (list == NULL) return NULL; - cx_for_n (i, num_items) { - if (0 != cxListAdd(list, ((const unsigned char *) array) + i * item_size)) { - cx_ll_destructor(list); - cxFree(allocator, list); - return NULL; - } - } - return list; -}