From ec5315a9870d42a8ba154c3456b36089a6066466 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 28 Mar 2021 08:01:55 -0700 Subject: [PATCH] Use strlen when possible in fallback basic_string_view --- include/fmt/core.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index d54a0784..42e930a9 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -395,8 +395,12 @@ template class basic_string_view { #if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr. FMT_CONSTEXPR #endif - FMT_INLINE basic_string_view(const Char* s) - : data_(s), size_(std::char_traits::length(s)) {} + FMT_INLINE basic_string_view(const Char* s) : data_(s) { + if (std::is_same::value) + size_ = std::strlen(reinterpret_cast(s)); + else + size_ = std::char_traits::length(s); + } /** Constructs a string reference from a ``std::basic_string`` object. */ template