From 6214f15a0c6ce8a156f21f22b2656f55301d3a4e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 9 May 2021 07:11:35 -0700 Subject: [PATCH] Optimize standard formatter specialization --- include/fmt/format.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index d802ee59..e31829e4 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2897,12 +2897,16 @@ struct formatter FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const -> decltype(ctx.out()) { - auto specs = specs_; - detail::handle_dynamic_spec(specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec( - specs.precision, specs.precision_ref, ctx); - return detail::write(ctx.out(), val, specs, ctx.locale()); + if (specs_.width_ref.kind != detail::arg_id_kind::none || + specs_.precision_ref.kind != detail::arg_id_kind::none) { + auto specs = specs_; + detail::handle_dynamic_spec(specs.width, + specs.width_ref, ctx); + detail::handle_dynamic_spec( + specs.precision, specs.precision_ref, ctx); + return detail::write(ctx.out(), val, specs, ctx.locale()); + } + return detail::write(ctx.out(), val, specs_, ctx.locale()); } private: