From efa13c663d8098a453c6e46769ee05165ecf47f9 Mon Sep 17 00:00:00 2001 From: Isaac Nickaein Date: Wed, 13 Nov 2019 15:23:08 +0330 Subject: [PATCH] Reserve stack only for top-level items --- include/nlohmann/json.hpp | 2 ++ single_include/nlohmann/json.hpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 5a66a860..eecff7fc 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1004,10 +1004,12 @@ 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)); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8acb1cc0..f9be0b4e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15547,10 +15547,12 @@ 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));