| 136 cxMapRemove(map, key); |
136 cxMapRemove(map, key); |
| 137 map->collection.simple_destructor = destr_bak; |
137 map->collection.simple_destructor = destr_bak; |
| 138 map->collection.advanced_destructor = destr2_bak; |
138 map->collection.advanced_destructor = destr2_bak; |
| 139 } |
139 } |
| 140 |
140 |
| 141 size_t cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func, |
141 int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func, |
| 142 const CxAllocator *clone_allocator, void *data) { |
142 const CxAllocator *clone_allocator, void *data) { |
| 143 CxMapIterator src_iter = cxMapIterator(src); |
143 CxMapIterator src_iter = cxMapIterator(src); |
| 144 size_t i = 0; |
|
| 145 if (cxCollectionStoresPointers(dst)) { |
144 if (cxCollectionStoresPointers(dst)) { |
| 146 for (; i < cxMapSize(src); i++) { |
145 for (size_t i = 0; i < cxMapSize(src); i++) { |
| 147 const CxMapEntry *entry = cxIteratorCurrent(src_iter); |
146 const CxMapEntry *entry = cxIteratorCurrent(src_iter); |
| 148 void **dst_mem = cxMapEmplace(dst, *(entry->key)); |
147 void **dst_mem = cxMapEmplace(dst, *(entry->key)); |
| 149 if (dst_mem == NULL) { |
148 if (dst_mem == NULL) { |
| 150 return i; |
149 return 1; |
| 151 } |
150 } |
| 152 void *dst_ptr = clone_func(NULL, entry->value, clone_allocator, data); |
151 void *dst_ptr = clone_func(NULL, entry->value, clone_allocator, data); |
| 153 if (dst_ptr == NULL) { |
152 if (dst_ptr == NULL) { |
| 154 cx_map_remove_uninitialized_entry(dst, *(entry->key)); |
153 cx_map_remove_uninitialized_entry(dst, *(entry->key)); |
| 155 return i; |
154 return 1; |
| 156 } |
155 } |
| 157 *dst_mem = dst_ptr; |
156 *dst_mem = dst_ptr; |
| 158 cxIteratorNext(src_iter); |
157 cxIteratorNext(src_iter); |
| 159 } |
158 } |
| 160 } else { |
159 } else { |
| 161 for (; i < cxMapSize(src); i++) { |
160 for (size_t i = 0; i < cxMapSize(src); i++) { |
| 162 const CxMapEntry *entry = cxIteratorCurrent(src_iter); |
161 const CxMapEntry *entry = cxIteratorCurrent(src_iter); |
| 163 void *dst_mem = cxMapEmplace(dst, *(entry->key)); |
162 void *dst_mem = cxMapEmplace(dst, *(entry->key)); |
| 164 if (dst_mem == NULL) { |
163 if (dst_mem == NULL) { |
| 165 return i; |
164 return 1; |
| 166 } |
165 } |
| 167 if (clone_func(dst_mem, entry->value, clone_allocator, data) == NULL) { |
166 if (clone_func(dst_mem, entry->value, clone_allocator, data) == NULL) { |
| 168 cx_map_remove_uninitialized_entry(dst, *(entry->key)); |
167 cx_map_remove_uninitialized_entry(dst, *(entry->key)); |
| 169 return i; |
168 return 1; |
| 170 } |
169 } |
| 171 cxIteratorNext(src_iter); |
170 cxIteratorNext(src_iter); |
| 172 } |
171 } |
| 173 } |
172 } |
| 174 return i; |
173 return 0; |
| 175 } |
174 } |