| 865 cx_list_pop_uninitialized_elements(dst, |
865 cx_list_pop_uninitialized_elements(dst, |
| 866 dst->collection.size - cloned - orig_size); |
866 dst->collection.size - cloned - orig_size); |
| 867 return 1; |
867 return 1; |
| 868 } |
868 } |
| 869 |
869 |
| |
870 // set the sorted flag when we know it's sorted |
| |
871 if (orig_size == 0 && src->collection.sorted) { |
| |
872 dst->collection.sorted = true; |
| |
873 } |
| |
874 |
| 870 return 0; |
875 return 0; |
| 871 } |
876 } |
| 872 |
877 |
| 873 int cxListDifference(CxList *dst, |
878 int cxListDifference(CxList *dst, |
| 874 const CxList *minuend, const CxList *subtrahend, |
879 const CxList *minuend, const CxList *subtrahend, |
| 1026 } else { |
1031 } else { |
| 1027 src_elem = cxIteratorCurrent(src_iter); |
1032 src_elem = cxIteratorCurrent(src_iter); |
| 1028 other_elem = cxIteratorCurrent(other_iter); |
1033 other_elem = cxIteratorCurrent(other_iter); |
| 1029 d = src->collection.cmpfunc(src_elem, other_elem); |
1034 d = src->collection.cmpfunc(src_elem, other_elem); |
| 1030 } |
1035 } |
| 1031 if (d <= 0) { |
1036 void *clone_from; |
| 1032 // source element is smaller or equal, clone it |
1037 if (d < 0) { |
| 1033 void **dst_mem = cxListEmplace(dst); |
1038 // source element is smaller clone it |
| 1034 void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; |
1039 clone_from = src_elem; |
| 1035 void* dst_ptr = clone_func(target, src_elem, clone_allocator, data); |
|
| 1036 if (dst_ptr == NULL) { |
|
| 1037 cx_list_pop_uninitialized_elements(dst, 1); |
|
| 1038 return 1; |
|
| 1039 } |
|
| 1040 if (cxCollectionStoresPointers(dst)) { |
|
| 1041 *dst_mem = dst_ptr; |
|
| 1042 } |
|
| 1043 cxIteratorNext(src_iter); |
1040 cxIteratorNext(src_iter); |
| 1044 // if the other element was equal, skip it |
1041 } else if (d == 0) { |
| 1045 if (d == 0) { |
1042 // both elements are equal, clone from the source, skip other |
| 1046 cxIteratorNext(other_iter); |
1043 clone_from = src_elem; |
| 1047 } |
1044 cxIteratorNext(src_iter); |
| |
1045 cxIteratorNext(other_iter); |
| 1048 } else { |
1046 } else { |
| 1049 // the other element is smaller, clone it |
1047 // the other element is smaller, clone it |
| 1050 void **dst_mem = cxListEmplace(dst); |
1048 clone_from = other_elem; |
| 1051 void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; |
|
| 1052 void* dst_ptr = clone_func(target, other_elem, clone_allocator, data); |
|
| 1053 if (dst_ptr == NULL) { |
|
| 1054 cx_list_pop_uninitialized_elements(dst, 1); |
|
| 1055 return 1; |
|
| 1056 } |
|
| 1057 if (cxCollectionStoresPointers(dst)) { |
|
| 1058 *dst_mem = dst_ptr; |
|
| 1059 } |
|
| 1060 cxIteratorNext(other_iter); |
1049 cxIteratorNext(other_iter); |
| |
1050 } |
| |
1051 void **dst_mem = cxListEmplace(dst); |
| |
1052 void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem; |
| |
1053 void* dst_ptr = clone_func(target, clone_from, clone_allocator, data); |
| |
1054 if (dst_ptr == NULL) { |
| |
1055 cx_list_pop_uninitialized_elements(dst, 1); |
| |
1056 return 1; |
| |
1057 } |
| |
1058 if (cxCollectionStoresPointers(dst)) { |
| |
1059 *dst_mem = dst_ptr; |
| 1061 } |
1060 } |
| 1062 } |
1061 } |
| 1063 |
1062 |
| 1064 // if dst was empty, it is now guaranteed to be sorted |
1063 // if dst was empty, it is now guaranteed to be sorted |
| 1065 dst->collection.sorted = dst_was_empty; |
1064 dst->collection.sorted = dst_was_empty; |