From 05bc87a66f53988dc04a9c73c91b38322ff8baa2 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 10 Mar 2021 17:59:36 -0800 Subject: [PATCH] Optimize padding --- include/fmt/format.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 90f83ca0..b143babd 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1612,14 +1612,14 @@ FMT_CONSTEXPR OutputIt write_padded(OutputIt out, static_assert(align == align::left || align == align::right, ""); unsigned spec_width = to_unsigned(specs.width); size_t padding = spec_width > width ? spec_width - width : 0; - size_t left_padding = 0; auto* shifts = align == align::left ? data::left_padding_shifts : data::right_padding_shifts; - left_padding = padding >> shifts[specs.align]; + size_t left_padding = padding >> shifts[specs.align]; + size_t right_padding = padding - left_padding; auto it = reserve(out, size + padding * specs.fill.size()); - it = fill(it, left_padding, specs.fill); + if (left_padding != 0) it = fill(it, left_padding, specs.fill); it = f(it); - it = fill(it, padding - left_padding, specs.fill); + if (right_padding != 0) it = fill(it, padding - left_padding, specs.fill); return base_iterator(out, it); }