Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
Update json library
Browse files Browse the repository at this point in the history
  • Loading branch information
r52 committed Nov 19, 2019
1 parent 7d47c49 commit 23ca444
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
__ _____ _____ _____
__| | __| | | | JSON for Modern C++
| | |__ | | | | | | version 3.7.1
| | |__ | | | | | | version 3.7.3
|_____|_____|_____|_|___| https://github.com/nlohmann/json

Licensed under the MIT License <http://opensource.org/licenses/MIT>.
Expand Down Expand Up @@ -32,7 +32,7 @@ SOFTWARE.

#define NLOHMANN_JSON_VERSION_MAJOR 3
#define NLOHMANN_JSON_VERSION_MINOR 7
#define NLOHMANN_JSON_VERSION_PATCH 1
#define NLOHMANN_JSON_VERSION_PATCH 3

#include <algorithm> // all_of, find, for_each
#include <cassert> // assert
Expand Down Expand Up @@ -15496,7 +15496,7 @@ class basic_json
object = nullptr; // silence warning, see #821
if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
{
JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.7.1")); // LCOV_EXCL_LINE
JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.7.3")); // LCOV_EXCL_LINE
}
break;
}
Expand Down Expand Up @@ -15541,6 +15541,53 @@ class basic_json

void destroy(value_t t) noexcept
{
// flatten the current json_value to a heap-allocated stack
std::vector<basic_json> stack;

// 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));
}
}

while (not stack.empty())
{
// move the last item to local variable to be processed
basic_json current_item(std::move(stack.back()));
stack.pop_back();

// if current_item is array/object, move
// 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));

current_item.m_value.array->clear();
}
else if (current_item.is_object())
{
for (auto&& it : *current_item.m_value.object)
{
stack.push_back(std::move(it.second));
}

current_item.m_value.object->clear();
}

// it's now safe that current_item get destructed
// since it doesn't have any children
}

switch (t)
{
case value_t::object:
Expand Down

0 comments on commit 23ca444

Please sign in to comment.