Move size_ initialization to initializer list (#2529)

This commit is contained in:
Vladislav Shchapov 2021-10-03 05:20:33 +05:00 committed by GitHub
parent 012cc709d0
commit 0a985fd4c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -433,13 +433,12 @@ template <typename Char> class basic_string_view {
*/
FMT_CONSTEXPR_CHAR_TRAITS
FMT_INLINE
basic_string_view(const Char* s) : data_(s) {
if (detail::const_check(std::is_same<Char, char>::value &&
!detail::is_constant_evaluated(true)))
size_ = std::strlen(reinterpret_cast<const char*>(s));
else
size_ = std::char_traits<Char>::length(s);
}
basic_string_view(const Char* s)
: data_(s),
size_(detail::const_check(std::is_same<Char, char>::value &&
!detail::is_constant_evaluated(true))
? std::strlen(reinterpret_cast<const char*>(s))
: std::char_traits<Char>::length(s)) {}
/** Constructs a string reference from a ``std::basic_string`` object. */
template <typename Traits, typename Alloc>

View File

@ -2109,8 +2109,7 @@ FMT_CONSTEXPR_CHAR_TRAITS auto write(OutputIt out, const Char* value)
if (!value) {
throw_format_error("string pointer is null");
} else {
auto length = std::char_traits<Char>::length(value);
out = write(out, basic_string_view<Char>(value, length));
out = write(out, basic_string_view<Char>(value));
}
return out;
}