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
897879bc
Commit
897879bc
authored
Jul 24, 2017
by
Nikita Ofitserov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make detail::json_ref do less work by deferring moves/copies
parent
0f4978e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
+22
-16
src/json.hpp
src/json.hpp
+22
-16
No files found.
src/json.hpp
View file @
897879bc
...
...
@@ -7088,50 +7088,55 @@ struct json_ref
typedef
BasicJsonType
value_type
;
json_ref
(
value_type
&&
value
)
:
value_
(
std
::
move
(
value
)
)
:
value_
ref_
(
&
value
)
,
is_rvalue_
(
true
)
{}
json_ref
(
const
value_type
&
value
)
:
value_
(
value
)
:
value_
ref_
(
const_cast
<
value_type
*>
(
&
value
)
)
,
is_rvalue_
(
false
)
{}
json_ref
(
std
::
initializer_list
<
json_ref
>
init
)
:
value_
(
init
)
:
owned_
value_
(
init
)
,
is_rvalue_
(
true
)
{}
{
value_ref_
=
&
owned_value_
;
}
template
<
class
...
Args
>
json_ref
(
Args
...
args
)
:
value_
(
std
::
forward
<
Args
>
(
args
)...)
:
owned_
value_
(
std
::
forward
<
Args
>
(
args
)...)
,
is_rvalue_
(
true
)
{}
{
value_ref_
=
&
owned_value_
;
}
value_type
moved
()
const
value_type
moved
_or_copied
()
const
{
if
(
is_rvalue_
)
{
return
std
::
move
(
value
_
);
return
std
::
move
(
*
value_ref
_
);
}
else
{
return
value
_
;
return
*
value_ref
_
;
}
}
value_type
const
&
operator
*
()
const
{
return
value_
;
return
*
static_cast
<
value_type
const
*>
(
value_ref_
)
;
}
value_type
const
*
operator
->
()
const
{
return
&
value_
;
return
static_cast
<
value_type
const
*>
(
value_ref_
)
;
}
private:
mutable
value_type
value_
;
value_type
*
value_ref_
;
mutable
value_type
owned_value_
;
bool
is_rvalue_
;
};
...
...
@@ -8747,7 +8752,7 @@ class basic_json
std
::
for_each
(
init
.
begin
(),
init
.
end
(),
[
this
](
const
detail
::
json_ref
<
basic_json
>&
element_ref
)
{
basic_json
element
=
element_ref
.
moved
();
basic_json
element
=
element_ref
.
moved
_or_copied
();
m_value
.
object
->
emplace
(
std
::
move
(
*
((
*
element
.
m_value
.
array
)[
0
].
m_value
.
string
)),
std
::
move
((
*
element
.
m_value
.
array
)[
1
]));
...
...
@@ -9010,7 +9015,7 @@ class basic_json
///////////////////////////////////////
basic_json
(
const
detail
::
json_ref
<
basic_json
>&
ref
)
:
basic_json
(
ref
.
moved
())
:
basic_json
(
ref
.
moved
_or_copied
())
{
}
...
...
@@ -11935,8 +11940,9 @@ class basic_json
{
if
(
is_object
()
and
init
.
size
()
==
2
and
(
*
init
.
begin
())
->
is_string
())
{
basic_json
&&
key
=
init
.
begin
()
->
moved
();
push_back
(
typename
object_t
::
value_type
(
std
::
move
(
key
.
get_ref
<
string_t
&>
()),
(
init
.
begin
()
+
1
)
->
moved
()));
basic_json
&&
key
=
init
.
begin
()
->
moved_or_copied
();
push_back
(
typename
object_t
::
value_type
(
std
::
move
(
key
.
get_ref
<
string_t
&>
()),
(
init
.
begin
()
+
1
)
->
moved_or_copied
()));
}
else
{
...
...
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