src/list.c

changeset 1454
808688e304d5
parent 1453
b6fc5b1d5c5d
--- 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