diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 9cb36273..6d324f9c 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -323,6 +323,8 @@ const char basic_data::background_color[] = "\x1b[48;2;"; template const char basic_data::reset_color[] = "\x1b[0m"; template const wchar_t basic_data::wreset_color[] = L"\x1b[0m"; template const char basic_data::signs[] = {0, '-', '+', ' '}; +template +const char basic_data::padding_shifts[] = {31, 31, 0, 1, 0}; template struct bits { static FMT_CONSTEXPR_DECL const int value = diff --git a/include/fmt/format.h b/include/fmt/format.h index 2143174a..c19a6604 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -776,6 +776,7 @@ template struct FMT_EXTERN_TEMPLATE_API basic_data { static const char reset_color[5]; static const wchar_t wreset_color[5]; static const char signs[]; + static const char padding_shifts[5]; }; FMT_EXTERN template struct basic_data; @@ -1598,15 +1599,9 @@ template class basic_writer { template void write_padded(const format_specs& specs, size_t size, size_t width, const F& f) { - size_t padding = 0; - size_t left_padding = 0; - if (unsigned spec_width = to_unsigned(specs.width)) { - padding = spec_width > width ? spec_width - width : 0; - if (specs.align == align::right) - left_padding = padding; - else if (specs.align == align::center) - left_padding = padding / 2; - } + unsigned spec_width = to_unsigned(specs.width); + size_t padding = spec_width > width ? spec_width - width : 0; + size_t left_padding = padding >> data::padding_shifts[specs.align]; auto&& it = reserve(size + padding * specs.fill.size()); it = fill(it, left_padding, specs.fill); // Dummy check to workaround a bug in MSVC2017. @@ -1639,9 +1634,7 @@ template class basic_writer { template ::value)> void write(T value, format_specs specs = {}) { - if (const_check(!is_supported_floating_point(value))) { - return; - } + if (const_check(!is_supported_floating_point(value))) return; float_specs fspecs = parse_float_type_spec(specs); fspecs.sign = specs.sign; if (std::signbit(value)) { // value < 0 is false for NaN so use signbit. @@ -1876,7 +1869,7 @@ class arg_formatter_base { void on_int() { if (formatter.specs_) - formatter.writer_.write_int(value, *formatter.specs_); + formatter.writer_.write_int(static_cast(value), *formatter.specs_); else formatter.writer_.write(value); }