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
481ace65
Unverified
Commit
481ace65
authored
7 years ago
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
only calculate array index string when needed #1098
parent
90eb0a91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
16 deletions
+22
-16
include/nlohmann/detail/iterators/iteration_proxy.hpp
include/nlohmann/detail/iterators/iteration_proxy.hpp
+11
-8
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+11
-8
No files found.
include/nlohmann/detail/iterators/iteration_proxy.hpp
View file @
481ace65
...
@@ -21,8 +21,10 @@ template<typename IteratorType> class iteration_proxy
...
@@ -21,8 +21,10 @@ template<typename IteratorType> class iteration_proxy
IteratorType
anchor
;
IteratorType
anchor
;
/// an index for arrays (used to create key names)
/// an index for arrays (used to create key names)
std
::
size_t
array_index
=
0
;
std
::
size_t
array_index
=
0
;
/// last stringified array index
mutable
std
::
size_t
array_index_last
=
0
;
/// a string representation of the array index
/// a string representation of the array index
std
::
string
array_index_str
=
"0"
;
mutable
std
::
string
array_index_str
=
"0"
;
/// an empty string (to return a reference for primitive values)
/// an empty string (to return a reference for primitive values)
const
std
::
string
empty_str
=
""
;
const
std
::
string
empty_str
=
""
;
...
@@ -39,13 +41,7 @@ template<typename IteratorType> class iteration_proxy
...
@@ -39,13 +41,7 @@ template<typename IteratorType> class iteration_proxy
iteration_proxy_internal
&
operator
++
()
iteration_proxy_internal
&
operator
++
()
{
{
++
anchor
;
++
anchor
;
++
array_index
;
assert
(
anchor
.
m_object
!=
nullptr
);
if
(
anchor
.
m_object
->
is_array
())
{
// update array index and string representation
array_index_str
=
std
::
to_string
(
++
array_index
);
}
return
*
this
;
return
*
this
;
}
}
...
@@ -65,7 +61,14 @@ template<typename IteratorType> class iteration_proxy
...
@@ -65,7 +61,14 @@ template<typename IteratorType> class iteration_proxy
{
{
// use integer array index as key
// use integer array index as key
case
value_t
:
:
array
:
case
value_t
:
:
array
:
{
if
(
array_index
!=
array_index_last
)
{
array_index_str
=
std
::
to_string
(
array_index
);
array_index_last
=
array_index
;
}
return
array_index_str
;
return
array_index_str
;
}
// use key from the object
// use key from the object
case
value_t
:
:
object
:
case
value_t
:
:
object
:
...
...
This diff is collapsed.
Click to expand it.
single_include/nlohmann/json.hpp
View file @
481ace65
...
@@ -4691,8 +4691,10 @@ template<typename IteratorType> class iteration_proxy
...
@@ -4691,8 +4691,10 @@ template<typename IteratorType> class iteration_proxy
IteratorType anchor;
IteratorType anchor;
/// an index for arrays (used to create key names)
/// an index for arrays (used to create key names)
std::size_t array_index = 0;
std::size_t array_index = 0;
/// last stringified array index
mutable std::size_t array_index_last = 0;
/// a string representation of the array index
/// a string representation of the array index
std
::
string
array_index_str
=
"0"
;
mutable
std::string array_index_str = "0";
/// an empty string (to return a reference for primitive values)
/// an empty string (to return a reference for primitive values)
const std::string empty_str = "";
const std::string empty_str = "";
...
@@ -4709,13 +4711,7 @@ template<typename IteratorType> class iteration_proxy
...
@@ -4709,13 +4711,7 @@ template<typename IteratorType> class iteration_proxy
iteration_proxy_internal& operator++()
iteration_proxy_internal& operator++()
{
{
++anchor;
++anchor;
++array_index;
assert
(
anchor
.
m_object
!=
nullptr
);
if
(
anchor
.
m_object
->
is_array
())
{
// update array index and string representation
array_index_str
=
std
::
to_string
(
++
array_index
);
}
return *this;
return *this;
}
}
...
@@ -4735,7 +4731,14 @@ template<typename IteratorType> class iteration_proxy
...
@@ -4735,7 +4731,14 @@ template<typename IteratorType> class iteration_proxy
{
{
// use integer array index as key
// use integer array index as key
case value_t::array:
case value_t::array:
{
if (array_index != array_index_last)
{
array_index_str = std::to_string(array_index);
array_index_last = array_index;
}
return array_index_str;
return array_index_str;
}
// use key from the object
// use key from the object
case value_t::object:
case value_t::object:
...
...
This diff is collapsed.
Click to expand it.
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