| 118 | /// write collection data for non-polymorphic, non-shared-ref elements. |
| 119 | template <typename T, typename Container> |
| 120 | inline void write_collection_data_fast(const Container &coll, WriteContext &ctx, |
| 121 | bool has_generics) { |
| 122 | static_assert(!is_polymorphic_v<T>, |
| 123 | "Fast path is for non-polymorphic types only"); |
| 124 | static_assert(!is_shared_ref_v<T>, |
| 125 | "Fast path is for non-shared-ref types only"); |
| 126 | |
| 127 | // write length |
| 128 | ctx.write_var_uint32(static_cast<uint32_t>(coll.size())); |
| 129 | |
| 130 | if (coll.empty()) { |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | // Check for null elements |
| 135 | bool has_null = false; |
| 136 | if constexpr (is_nullable_v<T>) { |
| 137 | for (const auto &elem : coll) { |
| 138 | if (is_null_value(elem)) { |
| 139 | has_null = true; |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // Build header bitmap |
| 146 | uint8_t bitmap = COLL_IS_SAME_TYPE; |
| 147 | if (has_null) { |
| 148 | bitmap |= COLL_HAS_NULL; |
| 149 | } |
| 150 | |
| 151 | // Determine if element type is declared |
| 152 | using ElemType = nullable_element_t<T>; |
| 153 | bool is_elem_declared = |
| 154 | has_generics && !need_type_for_collection_elem<ElemType>(); |
| 155 | if (is_elem_declared) { |
| 156 | bitmap |= COLL_DECL_ELEMENT_TYPE; |
| 157 | } |
| 158 | |
| 159 | // write header |
| 160 | ctx.write_uint8(bitmap); |
| 161 | |
| 162 | // write element type info if not declared |
| 163 | if (!is_elem_declared) { |
| 164 | Serializer<ElemType>::write_type_info(ctx); |
| 165 | } |
| 166 | |
| 167 | // write elements |
| 168 | if constexpr (is_nullable_v<T>) { |
| 169 | using Inner = nullable_element_t<T>; |
| 170 | if (has_null) { |
| 171 | for (const auto &elem : coll) { |
| 172 | if (is_null_value(elem)) { |
| 173 | ctx.write_int8(NULL_FLAG); |
| 174 | } else { |
| 175 | ctx.write_int8(NOT_NULL_VALUE_FLAG); |
| 176 | if (is_elem_declared) { |
| 177 | Serializer<Inner>::write_data(deref_nullable(elem), ctx); |
nothing calls this directly
no test coverage detected