Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
149ded85
Unverified
Commit
149ded85
authored
Jul 15, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
simplify destroy() function for primitive types
parent
db980739
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
70 deletions
+74
-70
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+37
-35
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+37
-35
No files found.
include/nlohmann/json.hpp
View file @
149ded85
...
...
@@ -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
)
{
...
...
single_include/nlohmann/json.hpp
View file @
149ded85
...
...
@@ -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)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment