| 826 } |
826 } |
| 827 list->collection.simple_destructor = destr_bak; |
827 list->collection.simple_destructor = destr_bak; |
| 828 list->collection.advanced_destructor = destr2_bak; |
828 list->collection.advanced_destructor = destr2_bak; |
| 829 } |
829 } |
| 830 |
830 |
| 831 static void* cx_list_simple_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) { |
831 static void* cx_list_shallow_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) { |
| 832 size_t elem_size = *(size_t*)data; |
832 size_t elem_size = *(size_t*)data; |
| 833 if (dst == NULL) dst = cxMalloc(al, elem_size); |
833 if (dst == NULL) dst = cxMalloc(al, elem_size); |
| 834 if (dst != NULL) memcpy(dst, src, elem_size); |
834 if (dst != NULL) memcpy(dst, src, elem_size); |
| 835 return dst; |
835 return dst; |
| 836 } |
836 } |
| 837 |
837 |
| 838 #define use_simple_clone_func(list) cx_list_simple_clone_func, NULL, (void*)&((list)->collection.elem_size) |
838 #define use_shallow_clone_func(list) cx_list_shallow_clone_func, NULL, (void*)&((list)->collection.elem_size) |
| 839 |
839 |
| 840 int cxListClone(CxList *dst, const CxList *src, cx_clone_func clone_func, |
840 int cxListClone(CxList *dst, const CxList *src, cx_clone_func clone_func, |
| 841 const CxAllocator *clone_allocator, void *data) { |
841 const CxAllocator *clone_allocator, void *data) { |
| 842 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; |
842 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; |
| 843 |
843 |
| 1095 |
1095 |
| 1096 return 0; |
1096 return 0; |
| 1097 } |
1097 } |
| 1098 |
1098 |
| 1099 int cxListCloneShallow(CxList *dst, const CxList *src) { |
1099 int cxListCloneShallow(CxList *dst, const CxList *src) { |
| 1100 return cxListClone(dst, src, use_simple_clone_func(src)); |
1100 return cxListClone(dst, src, use_shallow_clone_func(src)); |
| 1101 } |
1101 } |
| 1102 |
1102 |
| 1103 int cxListDifferenceShallow(CxList *dst, const CxList *minuend, const CxList *subtrahend) { |
1103 int cxListDifferenceShallow(CxList *dst, const CxList *minuend, const CxList *subtrahend) { |
| 1104 return cxListDifference(dst, minuend, subtrahend, use_simple_clone_func(minuend)); |
1104 return cxListDifference(dst, minuend, subtrahend, use_shallow_clone_func(minuend)); |
| 1105 } |
1105 } |
| 1106 |
1106 |
| 1107 int cxListIntersectionShallow(CxList *dst, const CxList *src, const CxList *other) { |
1107 int cxListIntersectionShallow(CxList *dst, const CxList *src, const CxList *other) { |
| 1108 return cxListIntersection(dst, src, other, use_simple_clone_func(src)); |
1108 return cxListIntersection(dst, src, other, use_shallow_clone_func(src)); |
| 1109 } |
1109 } |
| 1110 |
1110 |
| 1111 int cxListUnionShallow(CxList *dst, const CxList *src, const CxList *other) { |
1111 int cxListUnionShallow(CxList *dst, const CxList *src, const CxList *other) { |
| 1112 return cxListUnion(dst, src, other, use_simple_clone_func(src)); |
1112 return cxListUnion(dst, src, other, use_shallow_clone_func(src)); |
| 1113 } |
1113 } |
| 1114 |
1114 |
| 1115 int cxListReserve(CxList *list, size_t capacity) { |
1115 int cxListReserve(CxList *list, size_t capacity) { |
| 1116 if (list->cl->change_capacity == NULL) { |
1116 if (list->cl->change_capacity == NULL) { |
| 1117 return 0; |
1117 return 0; |