From 2c3a5698ef4956568d378148b6e271dd70868669 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sat, 4 Jan 2025 19:02:51 +0500 Subject: [PATCH] Simplify a copying the fill from basic_specs Signed-off-by: Vladislav Shchapov --- include/fmt/base.h | 6 ++++++ include/fmt/format.h | 13 +------------ include/fmt/std.h | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 00c51423eeca..a6948d40b462 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -842,6 +842,12 @@ class basic_specs { for (size_t i = 0; i < size; ++i) fill_data_[i & 3] = static_cast(s[i]); } + + FMT_CONSTEXPR void set_fill(const basic_specs& specs) { + set_fill_size(specs.fill_size()); + for (size_t i = 0; i < max_fill_size; ++i) + fill_data_[i] = specs.fill_data_[i]; + } }; // Format specifiers for built-in and string types. diff --git a/include/fmt/format.h b/include/fmt/format.h index 2fb85fef0350..c9a6054d1957 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3654,17 +3654,6 @@ void vformat_to(buffer& buf, basic_string_view fmt, parse_format_string( fmt, format_handler{parse_context(fmt), {out, args, loc}}); } - -template -void basic_specs_copy_fill(basic_specs& dst, const basic_specs& src) { - if (src.fill_size() == 1 && const_check(!std::is_same::value)) { - Char fill = src.fill_unit(); - dst.set_fill(basic_string_view(&fill, 1)); - return; - } - dst.set_fill(basic_string_view(src.fill(), src.fill_size())); -} - } // namespace detail FMT_BEGIN_EXPORT @@ -3971,7 +3960,7 @@ template struct nested_formatter { write(basic_appender(buf)); auto specs = format_specs(); specs.width = width_; - detail::basic_specs_copy_fill(specs, specs_); + specs.set_fill(specs_); specs.set_align(specs_.align()); return detail::write( ctx.out(), basic_string_view(buf.data(), buf.size()), specs); diff --git a/include/fmt/std.h b/include/fmt/std.h index bc277d646267..bb07fedc0c1b 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -696,7 +696,7 @@ template struct formatter, Char> { auto outer_specs = format_specs(); outer_specs.width = specs.width; - detail::basic_specs_copy_fill(outer_specs, specs); + outer_specs.set_fill(specs); outer_specs.set_align(specs.align()); specs.width = 0;