Optimize logging via logs::channel

Use constant-initialized severity subobjects instead of temporaries
This commit is contained in:
Nekotekina 2018-09-16 00:36:20 +03:00
parent b94e98aed5
commit ed8aa774bb
3 changed files with 15 additions and 19 deletions

View file

@ -23,14 +23,17 @@ namespace logs
struct channel;
// Message information (temporary data)
// Message information
struct message
{
channel* ch;
level sev;
private:
// Send log message to global logger instance
void broadcast(const char*, const fmt_type_info*, const u64*);
void broadcast(const char*, const fmt_type_info*, const u64*) const;
friend struct channel;
};
class listener
@ -67,22 +70,16 @@ namespace logs
{
}
// Formatting function
template<typename... Args>
SAFE_BUFFERS FORCE_INLINE void format(level sev, const char* fmt, const Args&... args)
{
if (UNLIKELY(sev <= enabled))
{
static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};
message{this, sev}.broadcast(fmt, type_list, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});
}
}
#define GEN_LOG_METHOD(_sev)\
template<typename... Args>\
SAFE_BUFFERS void _sev(const char* fmt, const Args&... args)\
const message msg_##_sev{this, level::_sev};\
template <typename... Args>\
void _sev(const char* fmt, const Args&... args)\
{\
return format<Args...>(level::_sev, fmt, args...);\
if (UNLIKELY(level::_sev <= enabled))\
{\
static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};\
msg_##_sev.broadcast(fmt, type_list, fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});\
}\
}
GEN_LOG_METHOD(fatal)