From 8b8b89cbf6139225c2cc0574a32596e6e0716757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A9=D0=B0=D0=BF=D0=BE=D0=B2?= Date: Sat, 2 Oct 2021 23:15:38 +0500 Subject: [PATCH] Move size_ initialization to initializer list --- include/fmt/core.h | 13 ++++++------- include/fmt/format.h | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 187bce4b..12ecdf43 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -426,13 +426,12 @@ template 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::value && - !detail::is_constant_evaluated(true))) - size_ = std::strlen(reinterpret_cast(s)); - else - size_ = std::char_traits::length(s); - } + basic_string_view(const Char* s) + : data_(s), + size_(detail::const_check(std::is_same::value && + !detail::is_constant_evaluated(true)) + ? std::strlen(reinterpret_cast(s)) + : std::char_traits::length(s)) {} /** Constructs a string reference from a ``std::basic_string`` object. */ template diff --git a/include/fmt/format.h b/include/fmt/format.h index 2f361e63..2bd5a26c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -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::length(value); - out = write(out, basic_string_view(value, length)); + out = write(out, basic_string_view(value)); } return out; }