Skip to content

Commit

Permalink
Workaround missed optimization in gcc (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Mar 4, 2018
1 parent bb47109 commit a103b9b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1187,11 +1187,16 @@ std::wstring vformat(wstring_view format_str, wformat_args args);
*/
template <typename... Args>
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<context, Args...> as(args...);
return vformat(format_str, as);
}
template <typename... Args>
inline std::wstring format(wstring_view format_str, const Args & ... args) {
return vformat(format_str, make_args<wcontext>(args...));
arg_store<wcontext, Args...> as(args...);
return vformat(format_str, as);
}

FMT_API void vprint(std::FILE *f, string_view format_str, format_args args);
Expand All @@ -1207,7 +1212,8 @@ FMT_API void vprint(std::FILE *f, string_view format_str, format_args args);
*/
template <typename... Args>
inline void print(std::FILE *f, string_view format_str, const Args & ... args) {
vprint(f, format_str, make_args(args...));
arg_store<context, Args...> as(args...);
vprint(f, format_str, as);
}

FMT_API void vprint(string_view format_str, format_args args);
Expand All @@ -1223,7 +1229,8 @@ FMT_API void vprint(string_view format_str, format_args args);
*/
template <typename... Args>
inline void print(string_view format_str, const Args & ... args) {
vprint(format_str, make_args(args...));
arg_store<context, Args...> as(args...);
vprint(format_str, as);
}
} // namespace fmt

Expand Down

0 comments on commit a103b9b

Please sign in to comment.