88#include < cstdint> // std::uint8_t, std::int64_t, std::uint64_t
99#include < iterator> // std::cbegin, std::cend, std::distance
1010#include < memory> // std::make_shared
11+ #include < ranges> // std::ranges
1112#include < utility> // std::move
1213
1314namespace sourcemeta ::jsonbinpack {
@@ -17,9 +18,7 @@ auto Encoder::BYTE_CHOICE_INDEX(const sourcemeta::core::JSON &document,
1718 -> void {
1819 assert (!options.choices .empty ());
1920 assert (is_byte (options.choices .size ()));
20- const auto iterator{std::find_if (
21- std::cbegin (options.choices ), std::cend (options.choices ),
22- [&document](const auto &choice) { return choice == document; })};
21+ const auto iterator{std::ranges::find (options.choices , document)};
2322 assert (iterator != std::cend (options.choices ));
2423 const auto cursor{std::distance (std::cbegin (options.choices ), iterator)};
2524 assert (
@@ -31,9 +30,10 @@ auto Encoder::LARGE_CHOICE_INDEX(const sourcemeta::core::JSON &document,
3130 const struct LARGE_CHOICE_INDEX &options)
3231 -> void {
3332 assert (options.choices .size () > 0 );
34- const auto iterator{std::find_if (
35- std::cbegin (options.choices ), std::cend (options.choices ),
36- [&document](const auto &choice) { return choice == document; })};
33+ const auto iterator{
34+ std::ranges::find_if (options.choices , [&document](const auto &choice) {
35+ return choice == document;
36+ })};
3737 assert (iterator != std::cend (options.choices ));
3838 const auto cursor{std::distance (std::cbegin (options.choices ), iterator)};
3939 assert (is_within (cursor, static_cast <std::uint64_t >(0 ),
@@ -46,9 +46,10 @@ auto Encoder::TOP_LEVEL_BYTE_CHOICE_INDEX(
4646 const struct TOP_LEVEL_BYTE_CHOICE_INDEX &options) -> void {
4747 assert (options.choices .size () > 0 );
4848 assert (is_byte (options.choices .size ()));
49- const auto iterator{std::find_if (
50- std::cbegin (options.choices ), std::cend (options.choices ),
51- [&document](auto const &choice) { return choice == document; })};
49+ const auto iterator{
50+ std::ranges::find_if (options.choices , [&document](auto const &choice) {
51+ return choice == document;
52+ })};
5253 assert (iterator != std::cend (options.choices ));
5354 const auto cursor{std::distance (std::cbegin (options.choices ), iterator)};
5455 assert (is_within (cursor, 0 ,
@@ -117,7 +118,7 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
117118 this ->put_varint (absolute);
118119 }
119120 } else if (document.is_string ()) {
120- const sourcemeta::core::JSON::String value{document.to_string ()};
121+ const sourcemeta::core::JSON::String & value{document.to_string ()};
121122 const auto size{document.byte_size ()};
122123 const auto shared{this ->cache_ .find (value, Cache::Type::Standalone)};
123124 if (size < uint_max<5 >) {
@@ -131,7 +132,8 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
131132 this ->cache_ .record (value, this ->position (), Cache::Type::Standalone);
132133 this ->put_string_utf8 (value, size);
133134 }
134- } else if (size >= uint_max<5 > && size < uint_max<5 > * 2 &&
135+ } else if (size >= uint_max<5 > &&
136+ size < static_cast <std::uint64_t >(uint_max<5 >) * 2 &&
135137 !shared.has_value ()) {
136138 this ->put_byte (static_cast <std::uint8_t >(
137139 TYPE_LONG_STRING | ((size - uint_max<5 >) << type_size)));
@@ -154,8 +156,8 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
154156 }
155157
156158 // If we got this far, the string is at least a certain length
157- return FLOOR_VARINT_PREFIX_UTF8_STRING_SHARED (document,
158- { uint_max<5 > * 2 });
159+ return FLOOR_VARINT_PREFIX_UTF8_STRING_SHARED (
160+ document, { static_cast <std:: uint64_t >( uint_max<5 > * 2 ) });
159161 }
160162 } else if (document.is_array ()) {
161163 const auto size{document.size ()};
@@ -170,7 +172,9 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
170172 Encoding encoding{
171173 sourcemeta::jsonbinpack::ANY_PACKED_TYPE_TAG_BYTE_PREFIX{}};
172174 this ->FIXED_TYPED_ARRAY (
173- document, {size, std::make_shared<Encoding>(std::move (encoding)), {}});
175+ document, {.size = size,
176+ .encoding = std::make_shared<Encoding>(std::move (encoding)),
177+ .prefix_encodings = {}});
174178 } else if (document.is_object ()) {
175179 const auto size{document.size ()};
176180 if (size >= uint_max<5 >) {
@@ -186,8 +190,10 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
186190 Encoding value_encoding{
187191 sourcemeta::jsonbinpack::ANY_PACKED_TYPE_TAG_BYTE_PREFIX{}};
188192 this ->FIXED_TYPED_ARBITRARY_OBJECT (
189- document, {size, std::make_shared<Encoding>(std::move (key_encoding)),
190- std::make_shared<Encoding>(std::move (value_encoding))});
193+ document,
194+ {.size = size,
195+ .key_encoding = std::make_shared<Encoding>(std::move (key_encoding)),
196+ .encoding = std::make_shared<Encoding>(std::move (value_encoding))});
191197 } else {
192198 // We should never get here
193199 unreachable ();
0 commit comments