src/list.c

changeset 890
54565fd74e74
parent 877
608b14deea18
--- a/src/list.c	Wed Sep 18 00:02:18 2024 +0200
+++ b/src/list.c	Sat Sep 28 15:47:28 2024 +0200
@@ -35,24 +35,24 @@
 static _Thread_local cx_compare_func cx_pl_cmpfunc_impl;
 
 static int cx_pl_cmpfunc(
-        void const *l,
-        void const *r
+        const void *l,
+        const void *r
 ) {
     void *const *lptr = l;
     void *const *rptr = r;
-    void const *left = lptr == NULL ? NULL : *lptr;
-    void const *right = rptr == NULL ? NULL : *rptr;
+    const void *left = lptr == NULL ? NULL : *lptr;
+    const void *right = rptr == NULL ? NULL : *rptr;
     return cx_pl_cmpfunc_impl(left, right);
 }
 
-static void cx_pl_hack_cmpfunc(struct cx_list_s const *list) {
+static void cx_pl_hack_cmpfunc(const struct cx_list_s *list) {
     // cast away const - this is the hacky thing
     struct cx_collection_s *l = (struct cx_collection_s*) &list->collection;
     cx_pl_cmpfunc_impl = l->cmpfunc;
     l->cmpfunc = cx_pl_cmpfunc;
 }
 
-static void cx_pl_unhack_cmpfunc(struct cx_list_s const *list) {
+static void cx_pl_unhack_cmpfunc(const struct cx_list_s *list) {
     // cast away const - this is the hacky thing
     struct cx_collection_s *l = (struct cx_collection_s*) &list->collection;
     l->cmpfunc = cx_pl_cmpfunc_impl;
@@ -65,7 +65,7 @@
 static int cx_pl_insert_element(
         struct cx_list_s *list,
         size_t index,
-        void const *element
+        const void *element
 ) {
     return list->climpl->insert_element(list, index, &element);
 }
@@ -73,7 +73,7 @@
 static size_t cx_pl_insert_array(
         struct cx_list_s *list,
         size_t index,
-        void const *array,
+        const void *array,
         size_t n
 ) {
     return list->climpl->insert_array(list, index, array, n);
@@ -81,7 +81,7 @@
 
 static size_t cx_pl_insert_sorted(
         struct cx_list_s *list,
-        void const *array,
+        const void *array,
         size_t n
 ) {
     cx_pl_hack_cmpfunc(list);
@@ -92,7 +92,7 @@
 
 static int cx_pl_insert_iter(
         struct cx_iterator_s *iter,
-        void const *elem,
+        const void *elem,
         int prepend
 ) {
     struct cx_list_s *list = iter->src_handle.m;
@@ -119,7 +119,7 @@
 }
 
 static void *cx_pl_at(
-        struct cx_list_s const *list,
+        const struct cx_list_s *list,
         size_t index
 ) {
     void **ptr = list->climpl->at(list, index);
@@ -128,7 +128,7 @@
 
 static ssize_t cx_pl_find_remove(
         struct cx_list_s *list,
-        void const *elem,
+        const void *elem,
         bool remove
 ) {
     cx_pl_hack_cmpfunc(list);
@@ -144,8 +144,8 @@
 }
 
 static int cx_pl_compare(
-        struct cx_list_s const *list,
-        struct cx_list_s const *other
+        const struct cx_list_s *list,
+        const struct cx_list_s *other
 ) {
     cx_pl_hack_cmpfunc(list);
     int ret = list->climpl->compare(list, other);
@@ -157,14 +157,14 @@
     list->climpl->reverse(list);
 }
 
-static void *cx_pl_iter_current(void const *it) {
-    struct cx_iterator_s const *iter = it;
+static void *cx_pl_iter_current(const void *it) {
+    const struct cx_iterator_s *iter = it;
     void **ptr = iter->base.current_impl(it);
     return ptr == NULL ? NULL : *ptr;
 }
 
 static struct cx_iterator_s cx_pl_iterator(
-        struct cx_list_s const *list,
+        const struct cx_list_s *list,
         size_t index,
         bool backwards
 ) {
@@ -215,7 +215,7 @@
 }
 
 static void *cx_emptyl_at(
-        __attribute__((__unused__)) struct cx_list_s const *list,
+        __attribute__((__unused__)) const struct cx_list_s *list,
         __attribute__((__unused__)) size_t index
 ) {
     return NULL;
@@ -223,18 +223,18 @@
 
 static ssize_t cx_emptyl_find_remove(
         __attribute__((__unused__)) struct cx_list_s *list,
-        __attribute__((__unused__)) void const *elem,
+        __attribute__((__unused__)) const void *elem,
         __attribute__((__unused__)) bool remove
 ) {
     return -1;
 }
 
-static bool cx_emptyl_iter_valid(__attribute__((__unused__)) void const *iter) {
+static bool cx_emptyl_iter_valid(__attribute__((__unused__)) const void *iter) {
     return false;
 }
 
 static CxIterator cx_emptyl_iterator(
-        struct cx_list_s const *list,
+        const struct cx_list_s *list,
         size_t index,
         __attribute__((__unused__)) bool backwards
 ) {
@@ -288,11 +288,11 @@
 size_t cx_list_default_insert_array(
         struct cx_list_s *list,
         size_t index,
-        void const *data,
+        const void *data,
         size_t n
 ) {
     size_t elem_size = list->collection.elem_size;
-    char const *src = data;
+    const char *src = data;
     size_t i = 0;
     for (; i < n; i++) {
         if (0 != invoke_list_func(insert_element,
@@ -305,7 +305,7 @@
 
 size_t cx_list_default_insert_sorted(
         struct cx_list_s *list,
-        void const *sorted_data,
+        const void *sorted_data,
         size_t n
 ) {
     // corner case
@@ -313,14 +313,14 @@
 
     size_t elem_size = list->collection.elem_size;
     cx_compare_func cmp = list->collection.cmpfunc;
-    char const *src = sorted_data;
+    const char *src = sorted_data;
 
     // track indices and number of inserted items
     size_t di = 0, si = 0, inserted = 0;
 
     // search the list for insertion points
     for (; di < list->collection.size; di++) {
-        void const *list_elm = invoke_list_func(at, list, di);
+        const void *list_elm = invoke_list_func(at, list, di);
 
         // compare current list element with first source element
         // if less or equal, skip
@@ -330,7 +330,7 @@
 
         // determine number of consecutive elements that can be inserted
         size_t ins = 1;
-        char const *next = src;
+        const char *next = src;
         while (++si < n) {
             next += elem_size;
             // once we become larger than the list elem, break
@@ -422,8 +422,8 @@
 }
 
 int cxListCompare(
-        CxList const *list,
-        CxList const *other
+        const CxList *list,
+        const CxList *other
 ) {
     bool cannot_optimize = false;
 

mercurial