| 1356 | } |
| 1357 | |
| 1358 | void copy_assignment(const basic_json& other) |
| 1359 | { |
| 1360 | if (other.storage_kind() == json_storage_kind::const_json_ref) |
| 1361 | { |
| 1362 | auto alloc = cast<long_string_storage>().get_allocator(); |
| 1363 | destroy(); |
| 1364 | uninitialized_copy_a(other.cast<const_json_ref_storage>().value(), alloc); |
| 1365 | } |
| 1366 | else if (other.storage_kind() == json_storage_kind::json_ref) |
| 1367 | { |
| 1368 | auto alloc = cast<long_string_storage>().get_allocator(); |
| 1369 | destroy(); |
| 1370 | uninitialized_copy_a(other.cast<json_ref_storage>().value(), alloc); |
| 1371 | } |
| 1372 | else if (is_primitive_storage(other.storage_kind())) |
| 1373 | { |
| 1374 | destroy(); |
| 1375 | std::memcpy(static_cast<void*>(this), &other, sizeof(basic_json)); |
| 1376 | } |
| 1377 | else if (storage_kind() == other.storage_kind()) |
| 1378 | { |
| 1379 | switch (other.storage_kind()) |
| 1380 | { |
| 1381 | case json_storage_kind::long_str: |
| 1382 | { |
| 1383 | auto alloc = cast<long_string_storage>().get_allocator(); |
| 1384 | destroy(); |
| 1385 | uninitialized_copy_a(other, alloc); |
| 1386 | break; |
| 1387 | } |
| 1388 | case json_storage_kind::byte_str: |
| 1389 | { |
| 1390 | auto alloc = cast<byte_string_storage>().get_allocator(); |
| 1391 | destroy(); |
| 1392 | uninitialized_copy_a(other, alloc); |
| 1393 | break; |
| 1394 | } |
| 1395 | case json_storage_kind::array: |
| 1396 | cast<array_storage>().assign(other.cast<array_storage>()); |
| 1397 | break; |
| 1398 | case json_storage_kind::object: |
| 1399 | cast<object_storage>().assign(other.cast<object_storage>()); |
| 1400 | break; |
| 1401 | default: |
| 1402 | JSONCONS_UNREACHABLE(); |
| 1403 | break; |
| 1404 | } |
| 1405 | } |
| 1406 | else if (is_trivial_storage(storage_kind())) // rhs is not trivial storage |
| 1407 | { |
| 1408 | destroy(); |
| 1409 | uninitialized_copy(other); |
| 1410 | } |
| 1411 | else // lhs and rhs are not trivial storage |
| 1412 | { |
| 1413 | auto alloc = get_allocator(); |
| 1414 | destroy(); |
| 1415 | uninitialized_copy_a(other, alloc); |
no test coverage detected