From a103b9bc4634c7f3ca38819e17073d4a9fa2ec15 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 4 Mar 2018 11:45:20 -0800 Subject: [PATCH] Workaround missed optimization in gcc (#668) --- include/fmt/core.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index e11a8986..b30ed4c8 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1187,11 +1187,16 @@ std::wstring vformat(wstring_view format_str, wformat_args args); */ template inline std::string format(string_view format_str, const Args & ... args) { - return vformat(format_str, make_args(args...)); + // This should be just + // return vformat(format_str, make_args(args...)); + // but gcc has trouble optimizing the latter, so break it down. + arg_store as(args...); + return vformat(format_str, as); } template inline std::wstring format(wstring_view format_str, const Args & ... args) { - return vformat(format_str, make_args(args...)); + arg_store as(args...); + return vformat(format_str, as); } FMT_API void vprint(std::FILE *f, string_view format_str, format_args args); @@ -1207,7 +1212,8 @@ FMT_API void vprint(std::FILE *f, string_view format_str, format_args args); */ template inline void print(std::FILE *f, string_view format_str, const Args & ... args) { - vprint(f, format_str, make_args(args...)); + arg_store as(args...); + vprint(f, format_str, as); } FMT_API void vprint(string_view format_str, format_args args); @@ -1223,7 +1229,8 @@ FMT_API void vprint(string_view format_str, format_args args); */ template inline void print(string_view format_str, const Args & ... args) { - vprint(format_str, make_args(args...)); + arg_store as(args...); + vprint(format_str, as); } } // namespace fmt