From 2838c2c8a5aec8d2c2896c52c66827d321816b66 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 10 Jul 2021 17:00:13 +0300 Subject: [PATCH] use vformat_to instead for format_to for better performance --- include/spdlog/logger.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 444d1711..9140e72e 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -23,7 +23,6 @@ #endif #include -#include #ifndef SPDLOG_NO_EXCEPTIONS # define SPDLOG_LOGGER_CATCH() \ @@ -241,8 +240,8 @@ public: // format to wmemory_buffer and convert to utf8 fmt::wmemory_buffer wbuf; - fmt::format_to(std::back_inserter(wbuf), fmt, std::forward(args)...); - + // fmt::format_to(std::back_inserter(wbuf), fmt, std::forward(args)...); + fmt::detail::vformat_to(wbuf, fmt::to_string_view(fmt), fmt::make_format_args(args...), {}); memory_buf_t buf; details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf); details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); @@ -341,7 +340,8 @@ protected: SPDLOG_TRY { memory_buf_t buf; - fmt::format_to(std::back_inserter(buf), fmt, std::forward(args)...); + // faster than fmt::format_to(std::back_inserter(buf), fmt, std::forward(args)...); + fmt::detail::vformat_to(buf, fmt::string_view(fmt), fmt::make_format_args(args...), {}); details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); log_it_(log_msg, log_enabled, traceback_enabled); }