Improved perf by using const char* instead of std::string& when accepting format strings

This commit is contained in:
gabi 2014-12-08 00:55:45 +02:00
parent 77886e766e
commit 4637cf35df
3 changed files with 23 additions and 23 deletions

View File

@ -71,7 +71,7 @@ public:
template <typename... Args>
void write(const std::string& fmt, const Args&... args)
void write(const char* fmt, const Args&... args)
{
if (!_enabled)
return;

View File

@ -67,7 +67,7 @@ inline void spdlog::logger::set_pattern(const std::string& pattern)
// cppformat API of the form logger.info("hello {} {}", "world", 1);
//
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl, const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl, const char* fmt, const Args&... args)
{
bool msg_enabled = should_log(lvl);
details::line_logger l(this, lvl, msg_enabled);
@ -76,61 +76,61 @@ inline spdlog::details::line_logger spdlog::logger::_log(level::level_enum lvl,
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::log(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::log(const char* fmt, const Args&... args)
{
return _log(level::ALWAYS, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::trace(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::trace(const char* fmt, const Args&... args)
{
return _log(level::TRACE, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::debug(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::debug(const char* fmt, const Args&... args)
{
return _log(level::DEBUG, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::info(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::info(const char* fmt, const Args&... args)
{
return _log(level::INFO, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::notice(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::notice(const char* fmt, const Args&... args)
{
return _log(level::NOTICE, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::warn(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::warn(const char* fmt, const Args&... args)
{
return _log(level::WARN, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::error(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::error(const char* fmt, const Args&... args)
{
return _log(level::ERR, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::critical(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::critical(const char* fmt, const Args&... args)
{
return _log(level::CRITICAL, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::alert(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::alert(const char* fmt, const Args&... args)
{
return _log(level::ALERT, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::emerg(const std::string& fmt, const Args&... args)
inline spdlog::details::line_logger spdlog::logger::emerg(const char* fmt, const Args&... args)
{
return _log(level::EMERG, fmt, args...);
}

View File

@ -65,16 +65,16 @@ public:
//Stop logging
void stop();
template <typename... Args> details::line_logger log(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger trace(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger debug(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger info(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger notice(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger warn(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger error(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger critical(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger alert(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger emerg(const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger log(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger trace(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger debug(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger info(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger notice(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger warn(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger error(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger critical(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger alert(const char* fmt, const Args&... args);
template <typename... Args> details::line_logger emerg(const char* fmt, const Args&... args);
//API to support logger.info() << ".." calls
@ -100,7 +100,7 @@ protected:
virtual void _set_formatter(formatter_ptr);
virtual void _stop();
details::line_logger _log(level::level_enum lvl);
template <typename... Args> details::line_logger _log(level::level_enum lvl, const std::string& fmt, const Args&... args);
template <typename... Args> details::line_logger _log(level::level_enum lvl, const char* fmt, const Args&... args);
friend details::line_logger;