Skip to content

Commit

Permalink
Remove harmful vector::reserve during destruction (nlohmann#1837)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickaein committed Nov 12, 2019
1 parent be61ad1 commit 0f3ec00
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 14 deletions.
7 changes: 0 additions & 7 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -1027,17 +1024,13 @@ 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));

current_item.m_value.array->clear();
}
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));
Expand Down
7 changes: 0 additions & 7 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -15570,17 +15567,13 @@ 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));

current_item.m_value.array->clear();
}
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));
Expand Down

0 comments on commit 0f3ec00

Please sign in to comment.