Skip to content

Commit 6e2e5c7

Browse files
StilesCrisisStilesCrisis
authored andcommitted
Specialize StrLen for char/wchar_t
Compilers generally provide a much smarter strlen than ours.
1 parent f349456 commit 6e2e5c7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

include/rapidjson/internal/strfunc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define RAPIDJSON_INTERNAL_STRFUNC_H_
1717

1818
#include "../stream.h"
19+
#include <cwchar>
1920

2021
RAPIDJSON_NAMESPACE_BEGIN
2122
namespace internal {
@@ -34,6 +35,16 @@ inline SizeType StrLen(const Ch* s) {
3435
return SizeType(p - s);
3536
}
3637

38+
template <>
39+
inline SizeType StrLen(const char* s) {
40+
return SizeType(std::strlen(s));
41+
}
42+
43+
template <>
44+
inline SizeType StrLen(const wchar_t* s) {
45+
return SizeType(std::wcslen(s));
46+
}
47+
3748
//! Returns number of code points in a encoded string.
3849
template<typename Encoding>
3950
bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {

0 commit comments

Comments
 (0)