Commit cf3ca3b7 authored by Nikita Ofitserov's avatar Nikita Ofitserov

Optimize json construction from rvalue string_t/array_t/object_t

parent 7b3cbfff
...@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment