mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 22:15:19 +00:00
Merge branch 'json-view/23-zmij' into json-view/24-view-token-digits
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -983,7 +983,8 @@ inline void shortest_digits(char* buf, int& len, int& decimal_exponent, double v
|
||||
std::size_t n = digits.size();
|
||||
while (d.significand >= 100)
|
||||
{
|
||||
const auto i = static_cast<std::size_t>(d.significand % 100) * 2;
|
||||
const std::uint64_t two_digits = d.significand % 100; // a variable: GCC calls a cast of the remainder useless where std::uint64_t is std::size_t
|
||||
const auto i = static_cast<std::size_t>(two_digits) * 2;
|
||||
d.significand /= 100;
|
||||
n -= 2;
|
||||
digits[n] = pairs[i];
|
||||
|
||||
@@ -202,8 +202,9 @@ class builder
|
||||
{
|
||||
const std::uint64_t done = static_cast<std::uint64_t>(at - b) + 1;
|
||||
const std::uint64_t guess = static_cast<std::uint64_t>(n) * static_cast<std::uint64_t>(e - b + 1) / done;
|
||||
const std::uint64_t grown = guess + (guess / 4) + 64; // a variable: GCC calls a cast of the sum useless where std::uint64_t is std::size_t
|
||||
doc.tape_size = n;
|
||||
doc.reserve((std::max)(static_cast<std::size_t>(guess + (guess / 4) + 64), n + (n / 2) + 64));
|
||||
doc.reserve((std::max)(static_cast<std::size_t>(grown), n + (n / 2) + 64));
|
||||
return doc.tape;
|
||||
}
|
||||
|
||||
@@ -425,6 +426,14 @@ class builder
|
||||
return w;
|
||||
}
|
||||
|
||||
/// a compile-time option as a runtime condition: testing the template
|
||||
/// argument directly makes a condition like `TrailingCommas && c == ']'`
|
||||
/// constant when the option is off, which MSVC reports as C4127
|
||||
static NLOHMANN_VIEW_ALWAYS_INLINE bool enabled(bool option) noexcept
|
||||
{
|
||||
return option;
|
||||
}
|
||||
|
||||
/// The parse state and the parser proper. The cursor is a local object of
|
||||
/// run() whose address never escapes (everything it calls out of line is a
|
||||
/// member of the builder and gets the positions it needs), so that the
|
||||
@@ -554,7 +563,7 @@ arr_next:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (TrailingCommas && cur() == ']')
|
||||
if (enabled(TrailingCommas) && cur() == ']')
|
||||
{
|
||||
++p;
|
||||
goto close_container;
|
||||
@@ -621,7 +630,7 @@ obj_next:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (TrailingCommas && cur() == '}')
|
||||
if (enabled(TrailingCommas) && cur() == '}')
|
||||
{
|
||||
++p;
|
||||
goto close_object;
|
||||
@@ -771,7 +780,7 @@ indent_done:
|
||||
{
|
||||
++p;
|
||||
}
|
||||
if (Comments && cur() == '/')
|
||||
if (enabled(Comments) && cur() == '/')
|
||||
{
|
||||
const unsigned char* const q = cold.comment(p);
|
||||
if (q == nullptr)
|
||||
|
||||
@@ -71,7 +71,8 @@ inline void build_object_index(document_data& d, node* obj)
|
||||
for (const node* k = document_data::first_child(obj), *end = document_data::child_end(obj); k != end; k = document_data::after(k + 1))
|
||||
{
|
||||
const char* const key = d.str(*k);
|
||||
std::size_t i = static_cast<std::size_t>(key_hash(key, k->len)) & mask;
|
||||
const std::uint64_t hash = key_hash(key, k->len); // (a cast of the call would be useless where std::uint64_t is std::size_t)
|
||||
std::size_t i = static_cast<std::size_t>(hash) & mask;
|
||||
bool duplicate = false;
|
||||
while (slots[i] != 0)
|
||||
{
|
||||
@@ -107,7 +108,8 @@ inline const node* find_indexed(const document_data& d, const node* obj, const c
|
||||
{
|
||||
const document_data::object_index& ix = d.indexes[obj->extra - 1u];
|
||||
const std::uint32_t* const slots = d.index_slots.data() + ix.start;
|
||||
std::size_t i = static_cast<std::size_t>(key_hash(key, n)) & ix.mask;
|
||||
const std::uint64_t hash = key_hash(key, n); // (a cast of the call would be useless where std::uint64_t is std::size_t)
|
||||
std::size_t i = static_cast<std::size_t>(hash) & ix.mask;
|
||||
for (;;)
|
||||
{
|
||||
const std::uint32_t s = slots[i];
|
||||
|
||||
@@ -69,7 +69,7 @@ index_status array_index(const StringType& s, std::size_t& idx) noexcept
|
||||
}
|
||||
v = (v * 10) + d;
|
||||
}
|
||||
if (v >= static_cast<std::uint64_t>((std::numeric_limits<std::size_t>::max)()))
|
||||
if (v >= (std::numeric_limits<std::size_t>::max)()) // (std::size_t converts to std::uint64_t implicitly)
|
||||
{
|
||||
return index_status::too_large;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user