Use strlen when possible in fallback basic_string_view

This commit is contained in:
Victor Zverovich 2021-03-28 08:01:55 -07:00
parent 4f8778bab9
commit ec5315a987

View File

@ -395,8 +395,12 @@ template <typename Char> class basic_string_view {
#if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr. #if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr.
FMT_CONSTEXPR FMT_CONSTEXPR
#endif #endif
FMT_INLINE basic_string_view(const Char* s) FMT_INLINE basic_string_view(const Char* s) : data_(s) {
: data_(s), size_(std::char_traits<Char>::length(s)) {} if (std::is_same<Char, char>::value)
size_ = std::strlen(reinterpret_cast<const char*>(s));
else
size_ = std::char_traits<Char>::length(s);
}
/** Constructs a string reference from a ``std::basic_string`` object. */ /** Constructs a string reference from a ``std::basic_string`` object. */
template <typename Traits, typename Alloc> template <typename Traits, typename Alloc>