remove unnecessary flag_removal function

Sat, 17 Feb 2024 20:51:27 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 17 Feb 2024 20:51:27 +0100
changeset 829
7d4e31d295af
parent 828
88fa3381206d
child 830
c4dae6fe6d5b

remove unnecessary flag_removal function

CHANGELOG file | annotate | diff | comparison | revisions
src/array_list.c file | annotate | diff | comparison | revisions
src/cx/iterator.h file | annotate | diff | comparison | revisions
src/hash_map.c file | annotate | diff | comparison | revisions
src/linked_list.c file | annotate | diff | comparison | revisions
--- a/CHANGELOG	Sat Feb 17 20:22:13 2024 +0100
+++ b/CHANGELOG	Sat Feb 17 20:51:27 2024 +0100
@@ -13,6 +13,7 @@
  * the cx_compare_func symbol is now also declared by compare.h
  * fixes wrong link from UCX 2 documentation to UCX 3 documentation
  * fixes critical bug that produced wrong results when comparing lists of different type but same size
+ * removes flag_removal function from iterator (unfortunately breaks binary compatibility)
  * removes CMake
  * removes GTest dependency
  * removes flags to disable SBO in tests
--- a/src/array_list.c	Sat Feb 17 20:22:13 2024 +0100
+++ b/src/array_list.c	Sat Feb 17 20:51:27 2024 +0100
@@ -492,15 +492,6 @@
     }
 }
 
-static bool cx_arl_iter_flag_rm(void *it) {
-    struct cx_iterator_base_s *iter = it;
-    if (iter->mutating) {
-        iter->remove = true;
-        return true;
-    } else {
-        return false;
-    }
-}
 
 static struct cx_iterator_s cx_arl_iterator(
         struct cx_list_s const *list,
@@ -515,7 +506,6 @@
     iter.base.valid = cx_arl_iter_valid;
     iter.base.current = cx_arl_iter_current;
     iter.base.next = backwards ? cx_arl_iter_prev : cx_arl_iter_next;
-    iter.base.flag_removal = cx_arl_iter_flag_rm;
     iter.base.remove = false;
     iter.base.mutating = false;
 
--- a/src/cx/iterator.h	Sat Feb 17 20:22:13 2024 +0100
+++ b/src/cx/iterator.h	Sat Feb 17 20:51:27 2024 +0100
@@ -71,14 +71,6 @@
     void (*next)(void *);
 
     /**
-     * Flag current element for removal, if possible.
-     *
-     * When valid returns false, the behavior of this function is undefined.
-     */
-    __attribute__ ((__nonnull__))
-    bool (*flag_removal)(void *);
-
-    /**
      * Indicates whether this iterator may remove elements.
      */
     bool mutating;
@@ -243,12 +235,11 @@
 #define cxIteratorNext(iter) (iter).base.next(&iter)
 
 /**
- * Flags the current element for removal.
+ * Flags the current element for removal, if this iterator is mutating.
  *
  * @param iter the iterator
- * @return false if this iterator cannot remove the element
  */
-#define cxIteratorFlagRemoval(iter) (iter).base.flag_removal(&iter)
+#define cxIteratorFlagRemoval(iter) (iter).base.remove |= (iter).base.mutating
 
 /**
  * Loops over an iterator.
--- a/src/hash_map.c	Sat Feb 17 20:22:13 2024 +0100
+++ b/src/hash_map.c	Sat Feb 17 20:51:27 2024 +0100
@@ -326,16 +326,6 @@
     }
 }
 
-static bool cx_hash_map_iter_flag_rm(void *it) {
-    struct cx_iterator_base_s *iter = it;
-    if (iter->mutating) {
-        iter->remove = true;
-        return true;
-    } else {
-        return false;
-    }
-}
-
 static CxIterator cx_hash_map_iterator(
         CxMap const *map,
         enum cx_map_iterator_type type
@@ -360,7 +350,6 @@
             assert(false);
     }
 
-    iter.base.flag_removal = cx_hash_map_iter_flag_rm;
     iter.base.remove = false;
     iter.base.mutating = false;
 
--- a/src/linked_list.c	Sat Feb 17 20:22:13 2024 +0100
+++ b/src/linked_list.c	Sat Feb 17 20:51:27 2024 +0100
@@ -866,16 +866,6 @@
     return node->payload;
 }
 
-static bool cx_ll_iter_flag_rm(void *it) {
-    struct cx_iterator_base_s *iter = it;
-    if (iter->mutating) {
-        iter->remove = true;
-        return true;
-    } else {
-        return false;
-    }
-}
-
 static CxIterator cx_ll_iterator(
         struct cx_list_s const *list,
         size_t index,
@@ -888,7 +878,6 @@
     iter.base.valid = cx_ll_iter_valid;
     iter.base.current = cx_ll_iter_current;
     iter.base.next = backwards ? cx_ll_iter_prev : cx_ll_iter_next;
-    iter.base.flag_removal = cx_ll_iter_flag_rm;
     iter.base.mutating = false;
     iter.base.remove = false;
     return iter;

mercurial