| 560 | /// Read map data for non-polymorphic, non-shared-ref maps |
| 561 | template <typename K, typename V, typename MapType> |
| 562 | inline MapType read_map_data_fast(ReadContext &ctx, uint32_t length) { |
| 563 | static_assert(!is_polymorphic_v<K> && !is_polymorphic_v<V>, |
| 564 | "Fast path is for non-polymorphic types only"); |
| 565 | static_assert(!is_shared_ref_v<K> && !is_shared_ref_v<V>, |
| 566 | "Fast path is for non-shared-ref types only"); |
| 567 | |
| 568 | MapType result; |
| 569 | if (length == 0) { |
| 570 | return result; |
| 571 | } |
| 572 | if (FORY_PREDICT_FALSE(!reserve_map(result, ctx, length))) { |
| 573 | return result; |
| 574 | } |
| 575 | |
| 576 | uint32_t len_counter = 0; |
| 577 | |
| 578 | while (len_counter < length) { |
| 579 | uint8_t header = ctx.read_uint8(ctx.error()); |
| 580 | if (FORY_PREDICT_FALSE(ctx.has_error())) { |
| 581 | return MapType{}; |
| 582 | } |
| 583 | |
| 584 | // Handle null entries - insert with default-constructed key/value |
| 585 | if ((header & KEY_NULL) && (header & VALUE_NULL)) { |
| 586 | // Both null - insert with default values |
| 587 | result.emplace(K{}, V{}); |
| 588 | len_counter++; |
| 589 | continue; |
| 590 | } |
| 591 | if (header & KEY_NULL) { |
| 592 | // Null key, non-null value |
| 593 | // Java writes: header, then type info (if not declared), then value data |
| 594 | bool value_declared = (header & DECL_VALUE_TYPE) != 0; |
| 595 | bool track_value_ref = (header & TRACKING_VALUE_REF) != 0; |
| 596 | |
| 597 | // Read type info if not declared |
| 598 | if (!value_declared) { |
| 599 | read_type_info<V>(ctx); |
| 600 | if (FORY_PREDICT_FALSE(ctx.has_error())) { |
| 601 | return MapType{}; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | // Read value - consume ref flag if tracking, then read data |
| 606 | V value; |
| 607 | if (track_value_ref) { |
| 608 | value = Serializer<V>::read(ctx, RefMode::Tracking, false); |
| 609 | } else { |
| 610 | value = Serializer<V>::read_data(ctx); |
| 611 | } |
| 612 | if (FORY_PREDICT_FALSE(ctx.has_error())) { |
| 613 | return MapType{}; |
| 614 | } |
| 615 | result.emplace(K{}, std::move(value)); |
| 616 | len_counter++; |
| 617 | continue; |
| 618 | } |
| 619 | if (header & VALUE_NULL) { |
nothing calls this directly
no test coverage detected