From b0d8628c498d1a2be3391a1949886843746b9878 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 Jan 2021 16:54:00 +0100 Subject: [PATCH] :ok_hand: address comments --- include/nlohmann/json.hpp | 9 ++------- single_include/nlohmann/json.hpp | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 81587ef26..16bf6af00 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3607,16 +3607,10 @@ class basic_json // remember array size before resizing const auto previous_size = m_value.array->size(); #endif - m_value.array->resize(idx + 1); -#if JSON_DIAGNOSTICS // set parent for values added above - for (auto i = previous_size; i <= idx; ++i) - { - set_parent(m_value.array->operator[](i)); - } -#endif + set_parents(begin() + previous_size, idx + 1 - previous_size); } return m_value.array->operator[](idx); @@ -5985,6 +5979,7 @@ class basic_json std::swap(m_value, other.m_value); set_parents(); + other.set_parents(); assert_invariant(); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f388b0d02..7617b8eda 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20362,16 +20362,10 @@ class basic_json // remember array size before resizing const auto previous_size = m_value.array->size(); #endif - m_value.array->resize(idx + 1); -#if JSON_DIAGNOSTICS // set parent for values added above - for (auto i = previous_size; i <= idx; ++i) - { - set_parent(m_value.array->operator[](i)); - } -#endif + set_parents(begin() + previous_size, idx + 1 - previous_size); } return m_value.array->operator[](idx); @@ -22740,6 +22734,7 @@ class basic_json std::swap(m_value, other.m_value); set_parents(); + other.set_parents(); assert_invariant(); }