src/map.c

changeset 1474
84de0ba791af
parent 1467
bb6f04c35310
equal deleted inserted replaced
1473:944f02992369 1474:84de0ba791af
265 *dst_mem = dst_ptr; 265 *dst_mem = dst_ptr;
266 } 266 }
267 } 267 }
268 return 0; 268 return 0;
269 } 269 }
270
271 int cxMapUnion(CxMap *dst, const CxMap *src,
272 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) {
273 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
274
275 CxMapIterator src_iter = cxMapIterator(src);
276 cx_foreach(const CxMapEntry *, entry, src_iter) {
277 if (cxMapContains(dst, *entry->key)) {
278 continue;
279 }
280 void** dst_mem = cxMapEmplace(dst, *entry->key);
281 if (dst_mem == NULL) {
282 return 1; // LCOV_EXCL_LINE
283 }
284 void *target = cxCollectionStoresPointers(dst) ? NULL : dst_mem;
285 void* dst_ptr = clone_func(target, entry->value, clone_allocator, data);
286 if (dst_ptr == NULL) {
287 cx_map_remove_uninitialized_entry(dst, *(entry->key));
288 return 1;
289 }
290 if (cxCollectionStoresPointers(dst)) {
291 *dst_mem = dst_ptr;
292 }
293 }
294 return 0;
295 }

mercurial