src/list.c

changeset 1454
808688e304d5
parent 1453
b6fc5b1d5c5d
equal deleted inserted replaced
1453:b6fc5b1d5c5d 1454:808688e304d5
898 } 898 }
899 } 899 }
900 900
901 // now perform the difference calculation 901 // now perform the difference calculation
902 if (cxCollectionSorted(minuend) && cxCollectionSorted(subtrahend)) { 902 if (cxCollectionSorted(minuend) && cxCollectionSorted(subtrahend)) {
903 bool dst_was_empty = cxCollectionSize(dst) == 0;
904
903 CxIterator min_iter = cxListIterator(minuend); 905 CxIterator min_iter = cxListIterator(minuend);
904 CxIterator sub_iter = cxListIterator(subtrahend); 906 CxIterator sub_iter = cxListIterator(subtrahend);
905 while (cxIteratorValid(min_iter)) { 907 while (cxIteratorValid(min_iter)) {
906 void *min_elem = cxIteratorCurrent(min_iter); 908 void *min_elem = cxIteratorCurrent(min_iter);
907 void *sub_elem; 909 void *sub_elem;
936 *dst_mem = dst_ptr; 938 *dst_mem = dst_ptr;
937 } 939 }
938 cxIteratorNext(min_iter); 940 cxIteratorNext(min_iter);
939 } 941 }
940 } 942 }
943
944 // if dst was empty, it is now guaranteed to be sorted
945 dst->collection.sorted = dst_was_empty;
941 } else { 946 } else {
942 CxIterator min_iter = cxListIterator(minuend); 947 CxIterator min_iter = cxListIterator(minuend);
943 cx_foreach(void *, elem, min_iter) { 948 cx_foreach(void *, elem, min_iter) {
944 if (cxListContains(subtrahend, elem)) { 949 if (cxListContains(subtrahend, elem)) {
945 continue; 950 continue;

mercurial