From 0f3ec003bb141f4da0bedf4eaaed9feaf7ccc2ab Mon Sep 17 00:00:00 2001 From: Isaac Nickaein Date: Tue, 12 Nov 2019 22:19:55 +0330 Subject: [PATCH] Remove harmful vector::reserve during destruction (#1837) --- include/nlohmann/json.hpp | 7 ------- single_include/nlohmann/json.hpp | 7 ------- 2 files changed, 14 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 5d07b8f9..b60122cc 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1004,13 +1004,10 @@ class basic_json // move the top-level items to stack if (t == value_t::array) { - stack.reserve(array->size()); std::move(array->begin(), array->end(), std::back_inserter(stack)); } else if (t == value_t::object) { - stack.reserve(object->size()); - for (auto&& it : *object) { stack.push_back(std::move(it.second)); @@ -1027,8 +1024,6 @@ class basic_json // its children to the stack to be processed later if (current_item.is_array()) { - stack.reserve(stack.size() + current_item.m_value.array->size()); - std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack)); @@ -1036,8 +1031,6 @@ class basic_json } else if (current_item.is_object()) { - stack.reserve(stack.size() + current_item.m_value.object->size()); - for (auto&& it : *current_item.m_value.object) { stack.push_back(std::move(it.second)); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 726a9632..d2d85b3d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15547,13 +15547,10 @@ class basic_json // move the top-level items to stack if (t == value_t::array) { - stack.reserve(array->size()); std::move(array->begin(), array->end(), std::back_inserter(stack)); } else if (t == value_t::object) { - stack.reserve(object->size()); - for (auto&& it : *object) { stack.push_back(std::move(it.second)); @@ -15570,8 +15567,6 @@ class basic_json // its children to the stack to be processed later if (current_item.is_array()) { - stack.reserve(stack.size() + current_item.m_value.array->size()); - std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack)); @@ -15579,8 +15574,6 @@ class basic_json } else if (current_item.is_object()) { - stack.reserve(stack.size() + current_item.m_value.object->size()); - for (auto&& it : *current_item.m_value.object) { stack.push_back(std::move(it.second));