Reserve stack only for top-level items

This commit is contained in:
Isaac Nickaein 2019-11-13 15:23:08 +03:30
parent 948f98cf4a
commit efa13c663d
2 changed files with 4 additions and 0 deletions

View file

@ -1004,10 +1004,12 @@ class basic_json
// move the top-level items to stack // move the top-level items to stack
if (t == value_t::array) if (t == value_t::array)
{ {
stack.reserve(array->size());
std::move(array->begin(), array->end(), std::back_inserter(stack)); std::move(array->begin(), array->end(), std::back_inserter(stack));
} }
else if (t == value_t::object) else if (t == value_t::object)
{ {
stack.reserve(object->size());
for (auto&& it : *object) for (auto&& it : *object)
{ {
stack.push_back(std::move(it.second)); stack.push_back(std::move(it.second));

View file

@ -15547,10 +15547,12 @@ class basic_json
// move the top-level items to stack // move the top-level items to stack
if (t == value_t::array) if (t == value_t::array)
{ {
stack.reserve(array->size());
std::move(array->begin(), array->end(), std::back_inserter(stack)); std::move(array->begin(), array->end(), std::back_inserter(stack));
} }
else if (t == value_t::object) else if (t == value_t::object)
{ {
stack.reserve(object->size());
for (auto&& it : *object) for (auto&& it : *object)
{ {
stack.push_back(std::move(it.second)); stack.push_back(std::move(it.second));