diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 96a215da..c9abd3e3 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2047,40 +2047,40 @@ template struct formatter { template struct formatter, Char> { private: - format_specs specs; - int precision = -1; + format_specs specs_; using arg_ref_type = detail::arg_ref; - arg_ref_type width_ref; - arg_ref_type precision_ref; - bool localized = false; - basic_string_view format_str; + arg_ref_type width_ref_; + arg_ref_type precision_ref_; + bool localized_ = false; + basic_string_view format_str_; + using duration = std::chrono::duration; - using iterator = typename basic_format_parse_context::iterator; struct parse_range { - iterator begin; - iterator end; + const Char* begin; + const Char* end; }; FMT_CONSTEXPR parse_range do_parse(basic_format_parse_context& ctx) { auto begin = ctx.begin(), end = ctx.end(); if (begin == end || *begin == '}') return {begin, begin}; - begin = detail::parse_align(begin, end, specs); + begin = detail::parse_align(begin, end, specs_); if (begin == end) return {begin, begin}; - begin = detail::parse_dynamic_spec(begin, end, specs.width, width_ref, ctx); + begin = + detail::parse_dynamic_spec(begin, end, specs_.width, width_ref_, ctx); if (begin == end) return {begin, begin}; auto checker = detail::chrono_format_checker(); if (*begin == '.') { checker.has_precision_integral = !std::is_floating_point::value; - begin = - detail::parse_precision(begin, end, precision, precision_ref, ctx); + begin = detail::parse_precision(begin, end, specs_.precision, + precision_ref_, ctx); } if (begin != end && *begin == 'L') { ++begin; - localized = true; + localized_ = true; } end = detail::parse_chrono_format(begin, end, checker); return {begin, end}; @@ -2090,7 +2090,7 @@ struct formatter, Char> { FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()) { auto range = do_parse(ctx); - format_str = basic_string_view( + format_str_ = basic_string_view( &*range.begin, detail::to_unsigned(range.end - range.begin)); return range.end; } @@ -2098,29 +2098,31 @@ struct formatter, Char> { template auto format(const duration& d, FormatContext& ctx) const -> decltype(ctx.out()) { - auto specs_copy = specs; - auto precision_copy = precision; - auto begin = format_str.begin(), end = format_str.end(); + auto specs = specs_; + auto precision = specs.precision; + specs.precision = -1; + auto begin = format_str_.begin(), end = format_str_.end(); // As a possible future optimization, we could avoid extra copying if width // is not specified. - basic_memory_buffer buf; + auto buf = basic_memory_buffer(); auto out = std::back_inserter(buf); - detail::handle_dynamic_spec(specs_copy.width, - width_ref, ctx); - detail::handle_dynamic_spec(precision_copy, - precision_ref, ctx); + detail::handle_dynamic_spec(specs.width, width_ref_, + ctx); + detail::handle_dynamic_spec(precision, + precision_ref_, ctx); if (begin == end || *begin == '}') { - out = detail::format_duration_value(out, d.count(), precision_copy); + out = detail::format_duration_value(out, d.count(), precision); detail::format_duration_unit(out); } else { - detail::chrono_formatter f( - ctx, out, d); - f.precision = precision_copy; - f.localized = localized; + using chrono_formatter = + detail::chrono_formatter; + auto f = chrono_formatter(ctx, out, d); + f.precision = precision; + f.localized = localized_; detail::parse_chrono_format(begin, end, f); } return detail::write( - ctx.out(), basic_string_view(buf.data(), buf.size()), specs_copy); + ctx.out(), basic_string_view(buf.data(), buf.size()), specs); } };