8
8
#include < cstdint> // std::uint8_t, std::int64_t, std::uint64_t
9
9
#include < iterator> // std::cbegin, std::cend, std::distance
10
10
#include < memory> // std::make_shared
11
+ #include < ranges> // std::ranges
11
12
#include < utility> // std::move
12
13
13
14
namespace sourcemeta ::jsonbinpack {
@@ -17,9 +18,7 @@ auto Encoder::BYTE_CHOICE_INDEX(const sourcemeta::core::JSON &document,
17
18
-> void {
18
19
assert (!options.choices .empty ());
19
20
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)};
23
22
assert (iterator != std::cend (options.choices ));
24
23
const auto cursor{std::distance (std::cbegin (options.choices ), iterator)};
25
24
assert (
@@ -31,9 +30,10 @@ auto Encoder::LARGE_CHOICE_INDEX(const sourcemeta::core::JSON &document,
31
30
const struct LARGE_CHOICE_INDEX &options)
32
31
-> void {
33
32
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
+ })};
37
37
assert (iterator != std::cend (options.choices ));
38
38
const auto cursor{std::distance (std::cbegin (options.choices ), iterator)};
39
39
assert (is_within (cursor, static_cast <std::uint64_t >(0 ),
@@ -46,9 +46,10 @@ auto Encoder::TOP_LEVEL_BYTE_CHOICE_INDEX(
46
46
const struct TOP_LEVEL_BYTE_CHOICE_INDEX &options) -> void {
47
47
assert (options.choices .size () > 0 );
48
48
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
+ })};
52
53
assert (iterator != std::cend (options.choices ));
53
54
const auto cursor{std::distance (std::cbegin (options.choices ), iterator)};
54
55
assert (is_within (cursor, 0 ,
@@ -117,7 +118,7 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
117
118
this ->put_varint (absolute);
118
119
}
119
120
} 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 ()};
121
122
const auto size{document.byte_size ()};
122
123
const auto shared{this ->cache_ .find (value, Cache::Type::Standalone)};
123
124
if (size < uint_max<5 >) {
@@ -131,7 +132,8 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
131
132
this ->cache_ .record (value, this ->position (), Cache::Type::Standalone);
132
133
this ->put_string_utf8 (value, size);
133
134
}
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 &&
135
137
!shared.has_value ()) {
136
138
this ->put_byte (static_cast <std::uint8_t >(
137
139
TYPE_LONG_STRING | ((size - uint_max<5 >) << type_size)));
@@ -154,8 +156,8 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
154
156
}
155
157
156
158
// 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 ) });
159
161
}
160
162
} else if (document.is_array ()) {
161
163
const auto size{document.size ()};
@@ -170,7 +172,9 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
170
172
Encoding encoding{
171
173
sourcemeta::jsonbinpack::ANY_PACKED_TYPE_TAG_BYTE_PREFIX{}};
172
174
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 = {}});
174
178
} else if (document.is_object ()) {
175
179
const auto size{document.size ()};
176
180
if (size >= uint_max<5 >) {
@@ -186,8 +190,10 @@ auto Encoder::ANY_PACKED_TYPE_TAG_BYTE_PREFIX(
186
190
Encoding value_encoding{
187
191
sourcemeta::jsonbinpack::ANY_PACKED_TYPE_TAG_BYTE_PREFIX{}};
188
192
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))});
191
197
} else {
192
198
// We should never get here
193
199
unreachable ();
0 commit comments