src/list.c

changeset 1479
ac1baaed2fd7
parent 1477
9170a7dff573
equal deleted inserted replaced
1478:bba2e5efdca0 1479:ac1baaed2fd7
817 } 817 }
818 list->collection.simple_destructor = destr_bak; 818 list->collection.simple_destructor = destr_bak;
819 list->collection.advanced_destructor = destr2_bak; 819 list->collection.advanced_destructor = destr2_bak;
820 } 820 }
821 821
822 static void* cx_list_simple_clone_func(void *dst, const void *src, const CxAllocator *al, void *data) {
823 size_t elem_size = *(size_t*)data;
824 if (dst == NULL) dst = cxMalloc(al, elem_size);
825 if (dst != NULL) memcpy(dst, src, elem_size);
826 return dst;
827 }
828
829 #define use_simple_clone_func(list) cx_list_simple_clone_func, NULL, (void*)&((list)->collection.elem_size)
830
822 int cxListClone(CxList *dst, const CxList *src, cx_clone_func clone_func, 831 int cxListClone(CxList *dst, const CxList *src, cx_clone_func clone_func,
823 const CxAllocator *clone_allocator, void *data) { 832 const CxAllocator *clone_allocator, void *data) {
824 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; 833 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
825 834
826 // remember the original size 835 // remember the original size
1076 } 1085 }
1077 } 1086 }
1078 1087
1079 return 0; 1088 return 0;
1080 } 1089 }
1090
1091 int cxListCloneSimple(CxList *dst, const CxList *src) {
1092 return cxListClone(dst, src, use_simple_clone_func(src));
1093 }
1094
1095 int cxListDifferenceSimple(CxList *dst, const CxList *minuend, const CxList *subtrahend) {
1096 return cxListDifference(dst, minuend, subtrahend, use_simple_clone_func(minuend));
1097 }
1098
1099 int cxListIntersectionSimple(CxList *dst, const CxList *src, const CxList *other) {
1100 return cxListIntersection(dst, src, other, use_simple_clone_func(src));
1101 }
1102
1103 int cxListUnionSimple(CxList *dst, const CxList *src, const CxList *other) {
1104 return cxListUnion(dst, src, other, use_simple_clone_func(src));
1105 }

mercurial