From 3135421257e71f456a4d745313d0be798354f34f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 11 Aug 2024 15:46:56 -0700 Subject: [PATCH] Minor cleanup --- include/fmt/base.h | 10 ++++------ include/fmt/format.h | 20 +++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index ab7a238f..e8dedc4a 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -926,9 +926,8 @@ template class buffer { /// Appends data to the end of the buffer. template -// Workaround for Visual Studio 2019 to fix error C2893: Failed to specialize -// function template 'void fmt::v11::detail::buffer::append(const U *,const -// U *)' +// Workaround for MSVC2019 to fix error C2893: Failed to specialize function +// template 'void fmt::v11::detail::buffer::append(const U *,const U *)'. #if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1930 FMT_CONSTEXPR20 #endif @@ -2285,7 +2284,7 @@ template FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int { if (const_check(sizeof(Char) != 1)) return 1; auto c = static_cast(*begin); - return static_cast((0x3a55000000000000ull >> (2 * (c >> 3))) & 0x3) + 1; + return static_cast((0x3a55000000000000ull >> (2 * (c >> 3))) & 3) + 1; } // Return the result via the out param to workaround gcc bug 77539. @@ -2880,8 +2879,7 @@ inline void report_truncation(bool truncated) { if (truncated) report_error("output is truncated"); } -// Use vformat_args and avoid type_identity to keep symbols short and workaround -// a GCC <= 4.8 bug. +// Use vformat_args and avoid type_identity to keep symbols short. template struct vformat_args { using type = basic_format_args>; }; diff --git a/include/fmt/format.h b/include/fmt/format.h index d5c746e1..b0bb6024 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2264,26 +2264,24 @@ FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, auto size = s.size(); if (specs.precision >= 0 && to_unsigned(specs.precision) < size) size = code_point_index(s, to_unsigned(specs.precision)); - bool is_debug = specs.type() == presentation_type::debug; - size_t width = 0; + bool is_debug = specs.type() == presentation_type::debug; if (is_debug) { auto buf = counting_buffer(); write_escaped_string(basic_appender(buf), s); size = buf.count(); } + size_t width = 0; if (specs.width != 0) { - if (is_debug) - width = size; - else - width = compute_width(basic_string_view(data, size)); + width = + is_debug ? size : compute_width(basic_string_view(data, size)); } - return write_padded(out, specs, size, width, - [=](reserve_iterator it) { - if (is_debug) return write_escaped_string(it, s); - return copy(data, data + size, it); - }); + return write_padded( + out, specs, size, width, [=](reserve_iterator it) { + return is_debug ? write_escaped_string(it, s) + : copy(data, data + size, it); + }); } template FMT_CONSTEXPR auto write(OutputIt out,