From 1e95c3d1ca76072c1899923658280358916967ab Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 29 Jun 2020 20:26:19 +0200 Subject: [PATCH] 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. --- lib/json/reflector.h | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/json/reflector.h b/lib/json/reflector.h index 3de7f37..bb201be 100644 --- a/lib/json/reflector.h +++ b/lib/json/reflector.h @@ -166,11 +166,11 @@ inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_ /*! * \brief Pushes the specified C-string to the specified value. */ -template > * = nullptr> +template , std::is_same> * = nullptr> inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator) { if (reflectable) { - value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable), allocator); + value.SetString(reflectable, allocator); } else { value.SetNull(); } @@ -183,28 +183,19 @@ template > inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator) { if (reflectable.data()) { - value.SetString(RAPIDJSON_NAMESPACE::StringRef(reflectable.data(), reflectable.size()), allocator); + value.SetString(reflectable.data(), rapidJsonSize(reflectable.size()), allocator); } else { value.SetNull(); } } -/*! - * \brief Pushes the specified constant C-string to the specified value. - */ -template > * = 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. */ template > * = nullptr> 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); } /*!