Merge develop; fix clang-tidy findings in json_view

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-25 19:03:32 +01:00
commit 4006a406a7
422 files changed
+2639 -837

No files matched your search

+19 -5
View File
@@ -650,9 +650,17 @@ class json_sax_dom_parser : public json_sax_dom_error_state
/// so that a big object can find the keys it has in a hash table instead of
/// searching all of them
template<typename ObjectType, typename StringType>
using detect_indexable_keys = decltype(std::declval<ObjectType&>().emplace_new_key(std::declval<const StringType&>(), std::declval<typename ObjectType::mapped_type>()),
std::hash<StringType>()(std::declval<const StringType&>()));
static constexpr bool indexed_keys = is_detected<detect_indexable_keys, object_t, string_t>::value;
using detect_emplace_new_key = decltype(std::declval<ObjectType&>().emplace_new_key(std::declval<const StringType&>(), std::declval<typename ObjectType::mapped_type>()));
template<typename StringType>
using detect_hash = decltype(std::hash<StringType>()(std::declval<const StringType&>()));
// std::hash is only named once the object can hold the keys in a vector:
// VS 2015 static-asserts on std::hash of a type without one instead of
// reporting a substitution failure
template<typename ObjectType, typename StringType, bool = is_detected<detect_emplace_new_key, ObjectType, StringType>::value>
struct detect_indexable_keys : std::false_type {};
template<typename ObjectType, typename StringType>
struct detect_indexable_keys<ObjectType, StringType, true> : is_detected<detect_hash, StringType> {};
static constexpr bool indexed_keys = detect_indexable_keys<object_t, string_t>::value;
/// what a frame holds for objects that are kept in a vector: the key index
/// of an object with many keys, and for an object that is collected on the
@@ -774,7 +782,10 @@ class json_sax_dom_parser : public json_sax_dom_error_state
{
const std::size_t new_capacity = capacity * 2;
std::unique_ptr<frame[]> new_heap(new frame[new_capacity]); // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
std::copy(data, data + count, new_heap.get());
for (std::size_t i = 0; i < count; ++i)
{
new_heap[i] = data[i];
}
heap = std::move(new_heap);
data = heap.get();
capacity = new_capacity;
@@ -792,7 +803,10 @@ class json_sax_dom_parser : public json_sax_dom_error_state
{
if (other.heap == nullptr)
{
std::copy(other.local.begin(), other.local.begin() + static_cast<std::ptrdiff_t>(other.count), local.begin());
for (std::size_t i = 0; i < other.count; ++i)
{
local[i] = other.local[i];
}
data = local.data();
capacity = local_capacity;
}
+1 -1
View File
@@ -549,7 +549,7 @@ run_found:
// the first growth: a decoded string is never longer than its source,
// so a fraction of the input (capped, as the buffer is zero-filled)
// covers the escapes of a typical document without regrowing it
wanted = (std::max)(wanted, (std::min)(static_cast<std::size_t>(m_end - m_begin) / 4 + 16, std::size_t{4096}));
wanted = (std::max)(wanted, (std::min)((static_cast<std::size_t>(m_end - m_begin) / 4) + 16, std::size_t{4096}));
}
m_doc.arena.resize((std::max)(m_doc.arena.size() * 2, wanted));
m_arena_write = m_doc.arena.data() + used;