Skip to content

Commit 3c78055

Browse files
phprusIniesta8
authored andcommitted
Move size_ initialization to initializer list (fmtlib#2529)
1 parent 6f55dd4 commit 3c78055

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

include/fmt/core.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,12 @@ template <typename Char> class basic_string_view {
433433
*/
434434
FMT_CONSTEXPR_CHAR_TRAITS
435435
FMT_INLINE
436-
basic_string_view(const Char* s) : data_(s) {
437-
if (detail::const_check(std::is_same<Char, char>::value &&
438-
!detail::is_constant_evaluated(true)))
439-
size_ = std::strlen(reinterpret_cast<const char*>(s));
440-
else
441-
size_ = std::char_traits<Char>::length(s);
442-
}
436+
basic_string_view(const Char* s)
437+
: data_(s),
438+
size_(detail::const_check(std::is_same<Char, char>::value &&
439+
!detail::is_constant_evaluated(true))
440+
? std::strlen(reinterpret_cast<const char*>(s))
441+
: std::char_traits<Char>::length(s)) {}
443442

444443
/** Constructs a string reference from a ``std::basic_string`` object. */
445444
template <typename Traits, typename Alloc>

include/fmt/format.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -2118,8 +2118,7 @@ FMT_CONSTEXPR_CHAR_TRAITS auto write(OutputIt out, const Char* value)
21182118
if (!value) {
21192119
throw_format_error("string pointer is null");
21202120
} else {
2121-
auto length = std::char_traits<Char>::length(value);
2122-
out = write(out, basic_string_view<Char>(value, length));
2121+
out = write(out, basic_string_view<Char>(value));
21232122
}
21242123
return out;
21252124
}

0 commit comments

Comments
 (0)