mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 00:40:26 +08:00
Optimize log(const T&) if can be statically converted to string_view
This commit is contained in:
parent
0584d6d89b
commit
8d2c956563
@ -71,7 +71,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Ar
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const char *msg)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
@ -81,13 +81,29 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *msg)
|
||||
|
||||
try
|
||||
{
|
||||
details::log_msg log_msg(&name_, lvl, msg);
|
||||
details::log_msg log_msg(&name_, lvl, spdlog::string_view_type(msg));
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
template<class T, typename std::enable_if<std::is_convertible<T, spdlog::string_view_type>::value, T>::type *>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const T &msg)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
details::log_msg log_msg(&name_, lvl, spdlog::string_view_type(msg));
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
template<class T, typename std::enable_if<!std::is_convertible<T, spdlog::string_view_type>::value, T>::type*>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const T &msg)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
@ -105,6 +121,9 @@ inline void spdlog::logger::log(level::level_enum lvl, const T &msg)
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::trace(const char *fmt, const Args &... args)
|
||||
{
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, const char *fmt, const Args &... args);
|
||||
|
||||
template<>
|
||||
void log(level::level_enum lvl, const char *msg);
|
||||
|
||||
template<typename... Args>
|
||||
@ -93,7 +94,12 @@ public:
|
||||
#endif // _WIN32
|
||||
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
|
||||
template<typename T>
|
||||
// T can be statically converted to string_view
|
||||
template<class T, typename std::enable_if<std::is_convertible<T, spdlog::string_view_type>::value, T>::type * = nullptr>
|
||||
void log(level::level_enum lvl, const T &);
|
||||
|
||||
// T cannot be statically converted to string_view
|
||||
template<class T, typename std::enable_if<!std::is_convertible<T, spdlog::string_view_type>::value, T>::type * = nullptr>
|
||||
void log(level::level_enum lvl, const T &);
|
||||
|
||||
template<typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user