From 5a2b88f6e9e6c27e55d5c72c3d1f03cf2396e3e8 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 29 May 2021 16:42:23 -0700 Subject: [PATCH] Reduce binary size --- include/fmt/format-inl.h | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index a3eaa361..2f63a213 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -2501,19 +2501,6 @@ int snprintf_float(T value, int precision, float_specs specs, return exp - fraction_size; } } - -struct stringifier { - template FMT_INLINE std::string operator()(T value) const { - return to_string(value); - } - std::string operator()(basic_format_arg::handle h) const { - memory_buffer buf; - format_parse_context parse_ctx({}); - format_context format_ctx(buffer_appender(buf), {}, {}); - h.format(parse_ctx, format_ctx); - return to_string(buf); - } -}; } // namespace detail template <> struct formatter { @@ -2577,12 +2564,9 @@ FMT_FUNC void report_system_error(int error_code, } FMT_FUNC std::string vformat(string_view fmt, format_args args) { - if (fmt.size() == 2 && detail::equal2(fmt.data(), "{}")) { - auto arg = args.get(0); - if (!arg) detail::error_handler().on_error("argument not found"); - return visit_format_arg(detail::stringifier(), arg); - } - memory_buffer buffer; + // Don't optimize the "{}" case to keep the binary size small and because it + // can be better optimized in fmt::format anyway. + auto buffer = memory_buffer(); detail::vformat_to(buffer, fmt, args); return to_string(buffer); }