cxListDifference() sets the sorted flag if it can guarantee that default tip

Sun, 26 Oct 2025 16:23:36 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 26 Oct 2025 16:23:36 +0100
changeset 1454
808688e304d5
parent 1453
b6fc5b1d5c5d

cxListDifference() sets the sorted flag if it can guarantee that

relates to #745

src/list.c file | annotate | diff | comparison | revisions
--- a/src/list.c	Sun Oct 26 16:16:43 2025 +0100
+++ b/src/list.c	Sun Oct 26 16:23:36 2025 +0100
@@ -900,6 +900,8 @@
 
     // now perform the difference calculation
     if (cxCollectionSorted(minuend) && cxCollectionSorted(subtrahend)) {
+        bool dst_was_empty = cxCollectionSize(dst) == 0;
+
         CxIterator min_iter = cxListIterator(minuend);
         CxIterator sub_iter = cxListIterator(subtrahend);
         while (cxIteratorValid(min_iter)) {
@@ -938,6 +940,9 @@
                 cxIteratorNext(min_iter);
             }
         }
+
+        // if dst was empty, it is now guaranteed to be sorted
+        dst->collection.sorted = dst_was_empty;
     } else {
         CxIterator min_iter = cxListIterator(minuend);
         cx_foreach(void *, elem, min_iter) {

mercurial