Merge branch 'perf/msgpack-scalar-runs' into perf/ubjson-typed-arrays
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+106
-8
No files matched your search
@@ -1707,12 +1707,15 @@ class binary_reader
|
|||||||
than 9 bytes (the longest of these values) are left in the input, leaving
|
than 9 bytes (the longest of these values) are left in the input, leaving
|
||||||
those to @ref parse_cbor_value, which reads them the same way.
|
those to @ref parse_cbor_value, which reads them the same way.
|
||||||
|
|
||||||
|
The caller has checked that an element remains, that at least 9 bytes are
|
||||||
|
left, and that the next byte begins a scalar.
|
||||||
|
|
||||||
@param[in,out] remaining the number of elements of the array not yet read
|
@param[in,out] remaining the number of elements of the array not yet read
|
||||||
@return whether the SAX parser accepted the values
|
@return whether the SAX parser accepted the values
|
||||||
*/
|
*/
|
||||||
bool parse_cbor_scalar_run(std::size_t& remaining)
|
bool parse_cbor_scalar_run(std::size_t& remaining)
|
||||||
{
|
{
|
||||||
while (remaining != 0 && ia.bulk_remaining() >= 9)
|
do
|
||||||
{
|
{
|
||||||
const auto* const data = reinterpret_cast<const unsigned char*>(ia.bulk_data());
|
const auto* const data = reinterpret_cast<const unsigned char*>(ia.bulk_data());
|
||||||
const unsigned char head = data[0];
|
const unsigned char head = data[0];
|
||||||
@@ -1800,6 +1803,7 @@ class binary_reader
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (remaining != 0 && ia.bulk_remaining() >= 9);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1816,7 +1820,27 @@ class binary_reader
|
|||||||
*/
|
*/
|
||||||
bool enter_cbor_array(const std::size_t len)
|
bool enter_cbor_array(const std::size_t len)
|
||||||
{
|
{
|
||||||
return enter_array(len) && (len == 0 || parse_cbor_array_start(std::integral_constant<bool, bulk_scan> {}));
|
return enter_array(len) && (len == 0 || !cbor_scalar_follows(std::integral_constant<bool, bulk_scan> {})
|
||||||
|
|| parse_cbor_array_start(std::integral_constant<bool, bulk_scan> {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// whether a run of scalars can start at the next byte: at least 9 bytes
|
||||||
|
/// are left and the byte begins an integer, a float, a boolean, or null;
|
||||||
|
/// one test, so that an array of containers or strings makes no call
|
||||||
|
bool cbor_scalar_follows(std::true_type /*bulk*/) const
|
||||||
|
{
|
||||||
|
if (ia.bulk_remaining() < 9)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto head = static_cast<unsigned char>(*ia.bulk_data());
|
||||||
|
return head < 0x40 || head >= 0xF4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// input that is not contiguous: every value is read by parse_cbor_value
|
||||||
|
bool cbor_scalar_follows(std::false_type /*bulk*/) const noexcept
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// read the scalars the array just opened begins with; out of line, so
|
/// read the scalars the array just opened begins with; out of line, so
|
||||||
@@ -2618,12 +2642,15 @@ class binary_reader
|
|||||||
than 9 bytes (the longest of these values) are left in the input, leaving
|
than 9 bytes (the longest of these values) are left in the input, leaving
|
||||||
those to @ref parse_msgpack_value, which reads them the same way.
|
those to @ref parse_msgpack_value, which reads them the same way.
|
||||||
|
|
||||||
|
The caller has checked that an element remains, that at least 9 bytes are
|
||||||
|
left, and that the next byte begins a scalar.
|
||||||
|
|
||||||
@param[in,out] remaining the number of elements of the array not yet read
|
@param[in,out] remaining the number of elements of the array not yet read
|
||||||
@return whether the SAX parser accepted the values
|
@return whether the SAX parser accepted the values
|
||||||
*/
|
*/
|
||||||
bool parse_msgpack_scalar_run(std::size_t& remaining)
|
bool parse_msgpack_scalar_run(std::size_t& remaining)
|
||||||
{
|
{
|
||||||
while (remaining != 0 && ia.bulk_remaining() >= 9)
|
do
|
||||||
{
|
{
|
||||||
const auto* const data = reinterpret_cast<const unsigned char*>(ia.bulk_data());
|
const auto* const data = reinterpret_cast<const unsigned char*>(ia.bulk_data());
|
||||||
const unsigned char head = data[0];
|
const unsigned char head = data[0];
|
||||||
@@ -2713,6 +2740,7 @@ class binary_reader
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (remaining != 0 && ia.bulk_remaining() >= 9);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2724,7 +2752,28 @@ class binary_reader
|
|||||||
*/
|
*/
|
||||||
bool enter_msgpack_array(const std::size_t len)
|
bool enter_msgpack_array(const std::size_t len)
|
||||||
{
|
{
|
||||||
return enter_array(len) && (len == 0 || parse_msgpack_array_start(std::integral_constant<bool, bulk_scan> {}));
|
return enter_array(len) && (len == 0 || !msgpack_scalar_follows(std::integral_constant<bool, bulk_scan> {})
|
||||||
|
|| parse_msgpack_array_start(std::integral_constant<bool, bulk_scan> {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// whether a run of scalars can start at the next byte: at least 9 bytes
|
||||||
|
/// are left and the byte begins a fixint, nil, a boolean, a float, or a
|
||||||
|
/// sized integer (0xC0-0xD3); one test, so that an array of containers or
|
||||||
|
/// strings makes no call
|
||||||
|
bool msgpack_scalar_follows(std::true_type /*bulk*/) const
|
||||||
|
{
|
||||||
|
if (ia.bulk_remaining() < 9)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto head = static_cast<unsigned char>(*ia.bulk_data());
|
||||||
|
return head < 0x80 || head >= 0xE0 || (head >= 0xC0 && head <= 0xD3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// input that is not contiguous: every value is read by parse_msgpack_value
|
||||||
|
bool msgpack_scalar_follows(std::false_type /*bulk*/) const noexcept
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// read the scalars the array just opened begins with; out of line, so
|
/// read the scalars the array just opened begins with; out of line, so
|
||||||
|
|||||||
Generated
+53
-4
@@ -19484,12 +19484,15 @@ class binary_reader
|
|||||||
than 9 bytes (the longest of these values) are left in the input, leaving
|
than 9 bytes (the longest of these values) are left in the input, leaving
|
||||||
those to @ref parse_cbor_value, which reads them the same way.
|
those to @ref parse_cbor_value, which reads them the same way.
|
||||||
|
|
||||||
|
The caller has checked that an element remains, that at least 9 bytes are
|
||||||
|
left, and that the next byte begins a scalar.
|
||||||
|
|
||||||
@param[in,out] remaining the number of elements of the array not yet read
|
@param[in,out] remaining the number of elements of the array not yet read
|
||||||
@return whether the SAX parser accepted the values
|
@return whether the SAX parser accepted the values
|
||||||
*/
|
*/
|
||||||
bool parse_cbor_scalar_run(std::size_t& remaining)
|
bool parse_cbor_scalar_run(std::size_t& remaining)
|
||||||
{
|
{
|
||||||
while (remaining != 0 && ia.bulk_remaining() >= 9)
|
do
|
||||||
{
|
{
|
||||||
const auto* const data = reinterpret_cast<const unsigned char*>(ia.bulk_data());
|
const auto* const data = reinterpret_cast<const unsigned char*>(ia.bulk_data());
|
||||||
const unsigned char head = data[0];
|
const unsigned char head = data[0];
|
||||||
@@ -19577,6 +19580,7 @@ class binary_reader
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (remaining != 0 && ia.bulk_remaining() >= 9);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19593,7 +19597,27 @@ class binary_reader
|
|||||||
*/
|
*/
|
||||||
bool enter_cbor_array(const std::size_t len)
|
bool enter_cbor_array(const std::size_t len)
|
||||||
{
|
{
|
||||||
return enter_array(len) && (len == 0 || parse_cbor_array_start(std::integral_constant<bool, bulk_scan> {}));
|
return enter_array(len) && (len == 0 || !cbor_scalar_follows(std::integral_constant<bool, bulk_scan> {})
|
||||||
|
|| parse_cbor_array_start(std::integral_constant<bool, bulk_scan> {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// whether a run of scalars can start at the next byte: at least 9 bytes
|
||||||
|
/// are left and the byte begins an integer, a float, a boolean, or null;
|
||||||
|
/// one test, so that an array of containers or strings makes no call
|
||||||
|
bool cbor_scalar_follows(std::true_type /*bulk*/) const
|
||||||
|
{
|
||||||
|
if (ia.bulk_remaining() < 9)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto head = static_cast<unsigned char>(*ia.bulk_data());
|
||||||
|
return head < 0x40 || head >= 0xF4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// input that is not contiguous: every value is read by parse_cbor_value
|
||||||
|
bool cbor_scalar_follows(std::false_type /*bulk*/) const noexcept
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// read the scalars the array just opened begins with; out of line, so
|
/// read the scalars the array just opened begins with; out of line, so
|
||||||
@@ -20395,12 +20419,15 @@ class binary_reader
|
|||||||
than 9 bytes (the longest of these values) are left in the input, leaving
|
than 9 bytes (the longest of these values) are left in the input, leaving
|
||||||
those to @ref parse_msgpack_value, which reads them the same way.
|
those to @ref parse_msgpack_value, which reads them the same way.
|
||||||
|
|
||||||
|
The caller has checked that an element remains, that at least 9 bytes are
|
||||||
|
left, and that the next byte begins a scalar.
|
||||||
|
|
||||||
@param[in,out] remaining the number of elements of the array not yet read
|
@param[in,out] remaining the number of elements of the array not yet read
|
||||||
@return whether the SAX parser accepted the values
|
@return whether the SAX parser accepted the values
|
||||||
*/
|
*/
|
||||||
bool parse_msgpack_scalar_run(std::size_t& remaining)
|
bool parse_msgpack_scalar_run(std::size_t& remaining)
|
||||||
{
|
{
|
||||||
while (remaining != 0 && ia.bulk_remaining() >= 9)
|
do
|
||||||
{
|
{
|
||||||
const auto* const data = reinterpret_cast<const unsigned char*>(ia.bulk_data());
|
const auto* const data = reinterpret_cast<const unsigned char*>(ia.bulk_data());
|
||||||
const unsigned char head = data[0];
|
const unsigned char head = data[0];
|
||||||
@@ -20490,6 +20517,7 @@ class binary_reader
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (remaining != 0 && ia.bulk_remaining() >= 9);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20501,7 +20529,28 @@ class binary_reader
|
|||||||
*/
|
*/
|
||||||
bool enter_msgpack_array(const std::size_t len)
|
bool enter_msgpack_array(const std::size_t len)
|
||||||
{
|
{
|
||||||
return enter_array(len) && (len == 0 || parse_msgpack_array_start(std::integral_constant<bool, bulk_scan> {}));
|
return enter_array(len) && (len == 0 || !msgpack_scalar_follows(std::integral_constant<bool, bulk_scan> {})
|
||||||
|
|| parse_msgpack_array_start(std::integral_constant<bool, bulk_scan> {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// whether a run of scalars can start at the next byte: at least 9 bytes
|
||||||
|
/// are left and the byte begins a fixint, nil, a boolean, a float, or a
|
||||||
|
/// sized integer (0xC0-0xD3); one test, so that an array of containers or
|
||||||
|
/// strings makes no call
|
||||||
|
bool msgpack_scalar_follows(std::true_type /*bulk*/) const
|
||||||
|
{
|
||||||
|
if (ia.bulk_remaining() < 9)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto head = static_cast<unsigned char>(*ia.bulk_data());
|
||||||
|
return head < 0x80 || head >= 0xE0 || (head >= 0xC0 && head <= 0xD3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// input that is not contiguous: every value is read by parse_msgpack_value
|
||||||
|
bool msgpack_scalar_follows(std::false_type /*bulk*/) const noexcept
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// read the scalars the array just opened begins with; out of line, so
|
/// read the scalars the array just opened begins with; out of line, so
|
||||||
|
|||||||
Reference in new issue
Block a user