From 6e2e5c7dbe08474249ca18b50da120b2c45ccc36 Mon Sep 17 00:00:00 2001 From: StilesCrisis Date: Tue, 28 Feb 2017 01:11:30 -0800 Subject: [PATCH] Specialize StrLen for char/wchar_t Compilers generally provide a much smarter strlen than ours. --- include/rapidjson/internal/strfunc.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/rapidjson/internal/strfunc.h b/include/rapidjson/internal/strfunc.h index de41d8f..226439a 100644 --- a/include/rapidjson/internal/strfunc.h +++ b/include/rapidjson/internal/strfunc.h @@ -16,6 +16,7 @@ #define RAPIDJSON_INTERNAL_STRFUNC_H_ #include "../stream.h" +#include RAPIDJSON_NAMESPACE_BEGIN namespace internal { @@ -34,6 +35,16 @@ inline SizeType StrLen(const Ch* s) { return SizeType(p - s); } +template <> +inline SizeType StrLen(const char* s) { + return SizeType(std::strlen(s)); +} + +template <> +inline SizeType StrLen(const wchar_t* s) { + return SizeType(std::wcslen(s)); +} + //! Returns number of code points in a encoded string. template bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {