Don't use StringRef with RapidJSON's SetString and allocator
There is no overload taking a RAPIDJSON_NAMESPACE::StringRef and an allocator. So the StringRef will be implicitly converted back to a plain CharType pointer causing an additional length calculation.
This commit is contained in:
parent
c33e1687cb
commit
1e95c3d1ca
|
@ -166,11 +166,11 @@ inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_
|
||||||
/*!
|
/*!
|
||||||
* \brief Pushes the specified C-string to the specified value.
|
* \brief Pushes the specified C-string to the specified value.
|
||||||
*/
|
*/
|
||||||
template <typename Type, Traits::EnableIf<std::is_same<Type, const char *>> * = nullptr>
|
template <typename Type, Traits::EnableIfAny<std::is_same<Type, const char *>, std::is_same<Type, const char *const &>> * = nullptr>
|
||||||
inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
|
inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
|
||||||
{
|
{
|
||||||
if (reflectable) {
|
if (reflectable) {
|
||||||
value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable), allocator);
|
value.SetString(reflectable, allocator);
|
||||||
} else {
|
} else {
|
||||||
value.SetNull();
|
value.SetNull();
|
||||||
}
|
}
|
||||||
|
@ -183,28 +183,19 @@ template <typename Type, Traits::EnableIf<std::is_same<Type, std::string_view>>
|
||||||
inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
|
inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
|
||||||
{
|
{
|
||||||
if (reflectable.data()) {
|
if (reflectable.data()) {
|
||||||
value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable.data(), reflectable.size()), allocator);
|
value.SetString(reflectable.data(), rapidJsonSize(reflectable.size()), allocator);
|
||||||
} else {
|
} else {
|
||||||
value.SetNull();
|
value.SetNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Pushes the specified constant C-string to the specified value.
|
|
||||||
*/
|
|
||||||
template <typename Type, Traits::EnableIf<std::is_same<Type, const char *const &>> * = nullptr>
|
|
||||||
inline void push(const char *const &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
|
|
||||||
{
|
|
||||||
value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable), allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Pushes the specified std::string to the specified value.
|
* \brief Pushes the specified std::string to the specified value.
|
||||||
*/
|
*/
|
||||||
template <typename Type, Traits::EnableIf<std::is_same<Type, std::string>> * = nullptr>
|
template <typename Type, Traits::EnableIf<std::is_same<Type, std::string>> * = nullptr>
|
||||||
inline void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
|
inline void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
|
||||||
{
|
{
|
||||||
value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable.data(), reflectable.size()), allocator);
|
value.SetString(reflectable.data(), rapidJsonSize(reflectable.size()), allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Reference in New Issue