From b9063f9392b50efacb6c11c69cb46627720eed9e Mon Sep 17 00:00:00 2001 From: Walter Gray Date: Sun, 20 Dec 2020 16:26:53 -0800 Subject: [PATCH] remove vformat from chrono.h --- include/fmt/chrono.h | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index d5c9d641..9574a7e0 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -768,24 +768,16 @@ inline std::chrono::duration get_milliseconds( template ::value)> OutputIt format_duration_value(OutputIt out, Rep val, int) { - static FMT_CONSTEXPR_DECL const Char format[] = {'{', '}', 0}; - return vformat_to(out, to_string_view(format), - make_format_args>(val)); + return write(out, val); } template ::value)> OutputIt format_duration_value(OutputIt out, Rep val, int precision) { - static FMT_CONSTEXPR_DECL const Char pr_f[] = {'{', ':', '.', '{', - '}', 'f', '}', 0}; - if (precision >= 0) { - return vformat_to(out, to_string_view(pr_f), - make_format_args>(val, precision)); - } - static FMT_CONSTEXPR_DECL const Char fp_f[] = {'{', ':', 'g', '}', 0}; - - return vformat_to(out, to_string_view(fp_f), - make_format_args>(val)); + basic_format_specs specs; + specs.precision = precision; + specs.type = precision > 0 ? 'f' : 'g'; + return write(out, val, specs); } template @@ -805,16 +797,20 @@ template OutputIt format_duration_unit(OutputIt out) { if (const char* unit = get_units()) return copy_unit(string_view(unit), out, Char()); - static FMT_CONSTEXPR_DECL const Char num_f[] = {'[', '{', '}', ']', 's', 0}; - if (const_check(Period::den == 1)) { - return vformat_to(out, to_string_view(num_f), - make_format_args>(Period::num)); + + basic_memory_buffer buffer; + auto bufOut = std::back_inserter(buffer); + *bufOut++ = '['; + bufOut = write(bufOut, Period::num); + + if (const_check(Period::den != 1)) { + *bufOut++ = '/'; + bufOut = write(bufOut, Period::den); } - static FMT_CONSTEXPR_DECL const Char num_def_f[] = {'[', '{', '}', '/', '{', - '}', ']', 's', 0}; - return vformat_to( - out, to_string_view(num_def_f), - make_format_args>(Period::num, Period::den)); + + *bufOut++ = ']'; + *bufOut++ = 's'; + return write(out, {buffer.data(), buffer.size()}); } template