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
cf3ca3b7
Commit
cf3ca3b7
authored
Jul 23, 2017
by
Nikita Ofitserov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize json construction from rvalue string_t/array_t/object_t
parent
7b3cbfff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
2 deletions
+62
-2
src/json.hpp
src/json.hpp
+62
-2
No files found.
src/json.hpp
View file @
cf3ca3b7
...
@@ -579,6 +579,14 @@ struct external_constructor<value_t::string>
...
@@ -579,6 +579,14 @@ struct external_constructor<value_t::string>
j
.
m_value
=
s
;
j
.
m_value
=
s
;
j
.
assert_invariant
();
j
.
assert_invariant
();
}
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
string_t
&&
s
)
{
j
.
m_type
=
value_t
::
string
;
j
.
m_value
=
std
::
move
(
s
);
j
.
assert_invariant
();
}
};
};
template
<
>
template
<
>
...
@@ -628,6 +636,14 @@ struct external_constructor<value_t::array>
...
@@ -628,6 +636,14 @@ struct external_constructor<value_t::array>
j
.
assert_invariant
();
j
.
assert_invariant
();
}
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
std
::
move
(
arr
);
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
not
std
::
is_same
<
CompatibleArrayType
,
enable_if_t
<
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJsonType
::
array_t
>
::
value
,
typename
BasicJsonType
::
array_t
>
::
value
,
...
@@ -666,6 +682,14 @@ struct external_constructor<value_t::object>
...
@@ -666,6 +682,14 @@ struct external_constructor<value_t::object>
j
.
assert_invariant
();
j
.
assert_invariant
();
}
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
object_t
&&
obj
)
{
j
.
m_type
=
value_t
::
object
;
j
.
m_value
=
std
::
move
(
obj
);
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
enable_if_t
<
not
std
::
is_same
<
CompatibleObjectType
,
enable_if_t
<
not
std
::
is_same
<
CompatibleObjectType
,
typename
BasicJsonType
::
object_t
>
::
value
,
typename
BasicJsonType
::
object_t
>
::
value
,
...
@@ -858,6 +882,12 @@ void to_json(BasicJsonType& j, const CompatibleString& s)
...
@@ -858,6 +882,12 @@ void to_json(BasicJsonType& j, const CompatibleString& s)
external_constructor
<
value_t
::
string
>::
construct
(
j
,
s
);
external_constructor
<
value_t
::
string
>::
construct
(
j
,
s
);
}
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
string_t
&&
s
)
{
external_constructor
<
value_t
::
string
>::
construct
(
j
,
std
::
move
(
s
));
}
template
<
typename
BasicJsonType
,
typename
FloatType
,
template
<
typename
BasicJsonType
,
typename
FloatType
,
enable_if_t
<
std
::
is_floating_point
<
FloatType
>
::
value
,
int
>
=
0
>
enable_if_t
<
std
::
is_floating_point
<
FloatType
>
::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
FloatType
val
)
noexcept
void
to_json
(
BasicJsonType
&
j
,
FloatType
val
)
noexcept
...
@@ -908,13 +938,25 @@ void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
...
@@ -908,13 +938,25 @@ void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
}
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&&
arr
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
std
::
move
(
arr
));
}
template
<
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
typename
BasicJsonType
,
typename
CompatibleObjectType
,
enable_if_t
<
is_compatible_object_type
<
BasicJsonType
,
CompatibleObjectType
>
::
value
,
enable_if_t
<
is_compatible_object_type
<
BasicJsonType
,
CompatibleObjectType
>
::
value
,
int
>
=
0
>
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
CompatibleObjectType
&
arr
)
void
to_json
(
BasicJsonType
&
j
,
const
CompatibleObjectType
&
obj
)
{
external_constructor
<
value_t
::
object
>::
construct
(
j
,
obj
);
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
object_t
&&
obj
)
{
{
external_constructor
<
value_t
::
object
>::
construct
(
j
,
arr
);
external_constructor
<
value_t
::
object
>::
construct
(
j
,
std
::
move
(
obj
)
);
}
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
...
@@ -8269,18 +8311,36 @@ class basic_json
...
@@ -8269,18 +8311,36 @@ class basic_json
string
=
create
<
string_t
>
(
value
);
string
=
create
<
string_t
>
(
value
);
}
}
/// constructor for rvalue strings
json_value
(
string_t
&&
value
)
{
string
=
create
<
string_t
>
(
std
::
move
(
value
));
}
/// constructor for objects
/// constructor for objects
json_value
(
const
object_t
&
value
)
json_value
(
const
object_t
&
value
)
{
{
object
=
create
<
object_t
>
(
value
);
object
=
create
<
object_t
>
(
value
);
}
}
/// constructor for rvalue objects
json_value
(
object_t
&&
value
)
{
object
=
create
<
object_t
>
(
std
::
move
(
value
));
}
/// constructor for arrays
/// constructor for arrays
json_value
(
const
array_t
&
value
)
json_value
(
const
array_t
&
value
)
{
{
array
=
create
<
array_t
>
(
value
);
array
=
create
<
array_t
>
(
value
);
}
}
/// constructor for rvalue arrays
json_value
(
array_t
&&
value
)
{
array
=
create
<
array_t
>
(
std
::
move
(
value
));
}
void
destroy
(
value_t
t
)
void
destroy
(
value_t
t
)
{
{
switch
(
t
)
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