simplify destroy() function for primitive types

parent db980739
......@@ -1132,6 +1132,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
void destroy(value_t t) noexcept
{
if (t == value_t::array || t == value_t::object)
{
// flatten the current json_value to a heap-allocated stack
std::vector<basic_json> stack;
......@@ -1142,7 +1144,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
stack.reserve(array->size());
std::move(array->begin(), array->end(), std::back_inserter(stack));
}
else if (t == value_t::object)
else
{
stack.reserve(object->size());
for (auto&& it : *object)
......@@ -1161,8 +1163,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// its children to the stack to be processed later
if (current_item.is_array())
{
std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(),
std::back_inserter(stack));
std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
current_item.m_value.array->clear();
}
......@@ -1179,6 +1180,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// it's now safe that current_item get destructed
// since it doesn't have any children
}
}
switch (t)
{
......
......@@ -18167,6 +18167,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
void destroy(value_t t) noexcept
{
if (t == value_t::array || t == value_t::object)
{
// flatten the current json_value to a heap-allocated stack
std::vector<basic_json> stack;
......@@ -18177,7 +18179,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
stack.reserve(array->size());
std::move(array->begin(), array->end(), std::back_inserter(stack));
}
else if (t == value_t::object)
else
{
stack.reserve(object->size());
for (auto&& it : *object)
......@@ -18196,8 +18198,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// its children to the stack to be processed later
if (current_item.is_array())
{
std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(),
std::back_inserter(stack));
std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
current_item.m_value.array->clear();
}
......@@ -18214,6 +18215,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// it's now safe that current_item get destructed
// since it doesn't have any children
}
}
switch (t)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment