src/list.c

changeset 1449
bbca398783ed
parent 1446
5732947cbcc2
child 1453
b6fc5b1d5c5d
equal deleted inserted replaced
1448:0f0fe7311b76 1449:bbca398783ed
818 // get an iterator over the source elements 818 // get an iterator over the source elements
819 CxIterator src_iter = cxListIterator(src); 819 CxIterator src_iter = cxListIterator(src);
820 820
821 // now clone the elements 821 // now clone the elements
822 size_t cloned = empl_iter.elem_count; 822 size_t cloned = empl_iter.elem_count;
823 if (cxCollectionStoresPointers(dst)) { 823 for (size_t i = 0 ; i < empl_iter.elem_count; i++) {
824 for (size_t i = 0 ; i < empl_iter.elem_count; i++) { 824 void *src_elem = cxIteratorCurrent(src_iter);
825 void *src_elem = cxIteratorCurrent(src_iter); 825 void **dest_memory = cxIteratorCurrent(empl_iter);
826 void **dest_memory = cxIteratorCurrent(empl_iter); 826 void *target = cxCollectionStoresPointers(dst) ? NULL : dest_memory;
827 void *dest_ptr = clone_func(NULL, src_elem, clone_allocator, data); 827 void *dest_ptr = clone_func(target, src_elem, clone_allocator, data);
828 if (dest_ptr == NULL) { 828 if (dest_ptr == NULL) {
829 cloned = i; 829 cloned = i;
830 break; 830 break;
831 } 831 }
832 if (cxCollectionStoresPointers(dst)) {
832 *dest_memory = dest_ptr; 833 *dest_memory = dest_ptr;
833 cxIteratorNext(src_iter); 834 }
834 cxIteratorNext(empl_iter); 835 cxIteratorNext(src_iter);
835 } 836 cxIteratorNext(empl_iter);
836 } else {
837 for (size_t i = 0 ; i < empl_iter.elem_count; i++) {
838 void *src_elem = cxIteratorCurrent(src_iter);
839 void *dest_memory = cxIteratorCurrent(empl_iter);
840 if (clone_func(dest_memory, src_elem, clone_allocator, data) == NULL) {
841 cloned = i;
842 break;
843 }
844 cxIteratorNext(src_iter);
845 cxIteratorNext(empl_iter);
846 }
847 } 837 }
848 838
849 // if we could not clone everything, free the allocated memory 839 // if we could not clone everything, free the allocated memory
850 // (disable the destructors!) 840 // (disable the destructors!)
851 if (cloned < src->collection.size) { 841 if (cloned < src->collection.size) {

mercurial