From 553038e810e8378fc2bb9a48353e39334e432524 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 8 Sep 2026 20:07:31 +0200 Subject: [PATCH] Inline from_json_object_impl into from_json now that it is called only once Addresses review feedback from @gregmarr on PR #5472: with the reserve loop de-duplicated, from_json_object_impl no longer needs to be a separate function that from_json immediately delegates to. Signed-off-by: Niels Lohmann --- .../nlohmann/detail/conversions/from_json.hpp | 22 +++++++------------ single_include/nlohmann/json.hpp | 22 +++++++------------ 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 75bd019eb..11e40f5f4 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -409,19 +409,6 @@ template inline void from_json_object_reserve(ConstructibleObjectType& /*obj*/, std::size_t /*size*/, priority_tag<0> /*unused*/) {} -template -inline void from_json_object_impl(const BasicJsonType& j, ConstructibleObjectType& obj) -{ - ConstructibleObjectType ret; - const auto* inner_object = j.template get_ptr(); - from_json_object_reserve(ret, inner_object->size(), priority_tag<1> {}); - for (const auto& p : *inner_object) - { - ret.emplace(p.first, p.second.template get()); - } - obj = std::move(ret); -} - template::value, int> = 0> inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) @@ -431,7 +418,14 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) JSON_THROW(type_error::create(302, concat("type must be object, but is ", j.type_name()), &j)); } - from_json_object_impl(j, obj); + ConstructibleObjectType ret; + const auto* inner_object = j.template get_ptr(); + from_json_object_reserve(ret, inner_object->size(), priority_tag<1> {}); + for (const auto& p : *inner_object) + { + ret.emplace(p.first, p.second.template get()); + } + obj = std::move(ret); } // overload for arithmetic types, not chosen for basic_json template arguments diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 79e838322..c8db9aab7 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -5704,19 +5704,6 @@ template inline void from_json_object_reserve(ConstructibleObjectType& /*obj*/, std::size_t /*size*/, priority_tag<0> /*unused*/) {} -template -inline void from_json_object_impl(const BasicJsonType& j, ConstructibleObjectType& obj) -{ - ConstructibleObjectType ret; - const auto* inner_object = j.template get_ptr(); - from_json_object_reserve(ret, inner_object->size(), priority_tag<1> {}); - for (const auto& p : *inner_object) - { - ret.emplace(p.first, p.second.template get()); - } - obj = std::move(ret); -} - template::value, int> = 0> inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) @@ -5726,7 +5713,14 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) JSON_THROW(type_error::create(302, concat("type must be object, but is ", j.type_name()), &j)); } - from_json_object_impl(j, obj); + ConstructibleObjectType ret; + const auto* inner_object = j.template get_ptr(); + from_json_object_reserve(ret, inner_object->size(), priority_tag<1> {}); + for (const auto& p : *inner_object) + { + ret.emplace(p.first, p.second.template get()); + } + obj = std::move(ret); } // overload for arithmetic types, not chosen for basic_json template arguments