simplifies linked list descriptor

Mon, 08 Feb 2021 00:18:09 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 08 Feb 2021 00:18:09 +0100
changeset 407
b447539ec255
parent 406
9cbea761fbf7
child 408
dfdd571550f8

simplifies linked list descriptor

src/cx/linked_list.h file | annotate | diff | comparison | revisions
src/linked_list.c file | annotate | diff | comparison | revisions
--- a/src/cx/linked_list.h	Mon Feb 08 00:14:07 2021 +0100
+++ b/src/cx/linked_list.h	Mon Feb 08 00:18:09 2021 +0100
@@ -39,8 +39,7 @@
 extern cx_list_class cx_linked_list_class;
 
 typedef struct {
-    void **begin;
-    void **end;
+    void *begin;
     ptrdiff_t loc_prev;
     ptrdiff_t loc_next;
     size_t item_size;
--- a/src/linked_list.c	Mon Feb 08 00:14:07 2021 +0100
+++ b/src/linked_list.c	Mon Feb 08 00:18:09 2021 +0100
@@ -155,7 +155,7 @@
 CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size) {
     CxLinkedListDesc desc;
     desc.item_size = item_size;
-    desc.begin = desc.end = NULL;
+    desc.begin = NULL;
     desc.loc_prev = offsetof(struct cx_linked_list_node, prev);
     desc.loc_next = offsetof(struct cx_linked_list_node, next);
 
@@ -174,8 +174,7 @@
     list->data.capacity = SIZE_MAX;
 
     cx_linked_list *ll = (cx_linked_list *) list->data.listdata;
-    ll->begin = desc.begin ? *desc.begin : NULL;
-    ll->end = desc.end ? *desc.end : NULL;
+    ll->begin = desc.begin;
     ll->loc_prev = desc.loc_prev;
     ll->loc_next = desc.loc_next;
     cxLinkedListRecalculateSize(list);
@@ -188,13 +187,17 @@
 
     if (ll->begin == NULL) {
         list->data.size = 0;
+        ll->end = NULL;
         return 0;
     } else {
         void *cur = ll->begin;
+        void *last;
         size_t size;
         do {
+            last = cur;
             size++;
         } while ((cur = *CX_LL_PTR(cur, ll->loc_next)) != NULL);
+        ll->end = last;
         list->data.size = size;
         return size;
     }

mercurial