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
3bb94670
Unverified
Commit
3bb94670
authored
Jul 13, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
move capacity check to set_parent function
parent
bc7e8faa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
68 deletions
+38
-68
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+19
-34
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+19
-34
No files found.
include/nlohmann/json.hpp
View file @
3bb94670
...
...
@@ -1304,9 +1304,21 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return
it
;
}
reference
set_parent
(
reference
j
)
reference
set_parent
(
reference
j
,
std
::
size_t
old_capacity
=
-
1
)
{
#if JSON_DIAGNOSTICS
if
(
old_capacity
!=
-
1
)
{
// see https://github.com/nlohmann/json/issues/2838
JSON_ASSERT
(
type
()
==
value_t
::
array
);
if
(
JSON_HEDLEY_UNLIKELY
(
m_value
.
array
->
capacity
()
!=
old_capacity
))
{
// capacity has changed: update all parents
set_parents
();
return
j
;
}
}
j
.
m_parent
=
this
;
#else
static_cast
<
void
>
(
j
);
...
...
@@ -5371,18 +5383,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
// add element to array (move semantics)
const
auto
capacity
=
m_value
.
array
->
capacity
();
const
auto
old_
capacity
=
m_value
.
array
->
capacity
();
m_value
.
array
->
push_back
(
std
::
move
(
val
));
if
(
capacity
==
m_value
.
array
->
capacity
())
{
// capacity has not changed: updating parent of last element is sufficient
set_parent
(
m_value
.
array
->
back
());
}
else
{
// capacity has changed: update all elements' parents
set_parents
();
}
set_parent
(
m_value
.
array
->
back
(),
old_capacity
);
// if val is moved from, basic_json move constructor marks it null so we do not call the destructor
}
...
...
@@ -5417,18 +5420,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
// add element to array
const
auto
capacity
=
m_value
.
array
->
capacity
();
const
auto
old_
capacity
=
m_value
.
array
->
capacity
();
m_value
.
array
->
push_back
(
val
);
if
(
capacity
==
m_value
.
array
->
capacity
())
{
// capacity has not changed: updating parent of last element is sufficient
set_parent
(
m_value
.
array
->
back
());
}
else
{
// capacity has changed: update all elements' parents
set_parents
();
}
set_parent
(
m_value
.
array
->
back
(),
old_capacity
);
}
/*!
...
...
@@ -5582,18 +5576,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
// add element to array (perfect forwarding)
const
auto
capacity
=
m_value
.
array
->
capacity
();
const
auto
old_
capacity
=
m_value
.
array
->
capacity
();
m_value
.
array
->
emplace_back
(
std
::
forward
<
Args
>
(
args
)...);
if
(
capacity
==
m_value
.
array
->
capacity
())
{
// capacity has not changed: updating parent of last element is sufficient
return
set_parent
(
m_value
.
array
->
back
());
}
// capacity has changed: update all elements' parents
set_parents
();
return
m_value
.
array
->
back
();
return
set_parent
(
m_value
.
array
->
back
(),
old_capacity
);
}
/*!
...
...
single_include/nlohmann/json.hpp
View file @
3bb94670
...
...
@@ -18339,9 +18339,21 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return
it
;
}
reference
set_parent
(
reference
j
)
reference
set_parent
(
reference
j
,
std
::
size_t
old_capacity
=
-
1
)
{
#if JSON_DIAGNOSTICS
if
(
old_capacity
!=
-
1
)
{
// see https://github.com/nlohmann/json/issues/2838
JSON_ASSERT
(
type
()
==
value_t
::
array
);
if
(
JSON_HEDLEY_UNLIKELY
(
m_value
.
array
->
capacity
()
!=
old_capacity
))
{
// capacity has changed: update all parents
set_parents
();
return
j
;
}
}
j
.
m_parent
=
this
;
#else
static_cast
<
void
>
(
j
);
...
...
@@ -22406,18 +22418,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
// add element to array (move semantics)
const
auto
capacity
=
m_value
.
array
->
capacity
();
const
auto
old_
capacity
=
m_value
.
array
->
capacity
();
m_value
.
array
->
push_back
(
std
::
move
(
val
));
if
(
capacity
==
m_value
.
array
->
capacity
())
{
// capacity has not changed: updating parent of last element is sufficient
set_parent
(
m_value
.
array
->
back
());
}
else
{
// capacity has changed: update all elements' parents
set_parents
();
}
set_parent
(
m_value
.
array
->
back
(),
old_capacity
);
// if val is moved from, basic_json move constructor marks it null so we do not call the destructor
}
...
...
@@ -22452,18 +22455,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
// add element to array
const
auto
capacity
=
m_value
.
array
->
capacity
();
const
auto
old_
capacity
=
m_value
.
array
->
capacity
();
m_value
.
array
->
push_back
(
val
);
if
(
capacity
==
m_value
.
array
->
capacity
())
{
// capacity has not changed: updating parent of last element is sufficient
set_parent
(
m_value
.
array
->
back
());
}
else
{
// capacity has changed: update all elements' parents
set_parents
();
}
set_parent
(
m_value
.
array
->
back
(),
old_capacity
);
}
/*!
...
...
@@ -22617,18 +22611,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
// add element to array (perfect forwarding)
const
auto
capacity
=
m_value
.
array
->
capacity
();
const
auto
old_
capacity
=
m_value
.
array
->
capacity
();
m_value
.
array
->
emplace_back
(
std
::
forward
<
Args
>
(
args
)...);
if
(
capacity
==
m_value
.
array
->
capacity
())
{
// capacity has not changed: updating parent of last element is sufficient
return
set_parent
(
m_value
.
array
->
back
());
}
// capacity has changed: update all elements' parents
set_parents
();
return
m_value
.
array
->
back
();
return
set_parent
(
m_value
.
array
->
back
(),
old_capacity
);
}
/*!
...
...
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