diff -r b6fc5b1d5c5d -r 808688e304d5 src/list.c --- 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) {