Skip to content

Commit

Permalink
Simplify a copying the fill from basic_specs
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Shchapov <[email protected]>
  • Loading branch information
phprus authored and vitaut committed Jan 5, 2025
1 parent fc1b0f3 commit 2c3a569
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
6 changes: 6 additions & 0 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ class basic_specs {
for (size_t i = 0; i < size; ++i)
fill_data_[i & 3] = static_cast<char>(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.
Expand Down
13 changes: 1 addition & 12 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3654,17 +3654,6 @@ void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
parse_format_string(
fmt, format_handler<Char>{parse_context<Char>(fmt), {out, args, loc}});
}

template <typename Char>
void basic_specs_copy_fill(basic_specs& dst, const basic_specs& src) {
if (src.fill_size() == 1 && const_check(!std::is_same<Char, char>::value)) {
Char fill = src.fill_unit<Char>();
dst.set_fill(basic_string_view<Char>(&fill, 1));
return;
}
dst.set_fill(basic_string_view<char>(src.fill<char>(), src.fill_size()));
}

} // namespace detail

FMT_BEGIN_EXPORT
Expand Down Expand Up @@ -3971,7 +3960,7 @@ template <typename T, typename Char = char> struct nested_formatter {
write(basic_appender<Char>(buf));
auto specs = format_specs();
specs.width = width_;
detail::basic_specs_copy_fill<Char>(specs, specs_);
specs.set_fill(specs_);
specs.set_align(specs_.align());
return detail::write<Char>(
ctx.out(), basic_string_view<Char>(buf.data(), buf.size()), specs);
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ template <typename T, typename Char> struct formatter<std::complex<T>, Char> {

auto outer_specs = format_specs();
outer_specs.width = specs.width;
detail::basic_specs_copy_fill<Char>(outer_specs, specs);
outer_specs.set_fill(specs);
outer_specs.set_align(specs.align());

specs.width = 0;
Expand Down

0 comments on commit 2c3a569

Please sign in to comment.