From 51f9f35599bdbc94e9c9698f9713141b960cf46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BOULMIER?= Date: Wed, 15 May 2019 20:42:29 -0400 Subject: [PATCH] cleanup(logger): use universal references to avoid useless copies --- include/components/logger.hpp | 33 +++++++++++++++++---------------- src/components/logger.cpp | 4 ++-- src/modules/fs.cpp | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/include/components/logger.hpp b/include/components/logger.hpp index 790e945f..437446ce 100644 --- a/include/components/logger.hpp +++ b/include/components/logger.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "common.hpp" #include "settings.hpp" @@ -34,51 +35,51 @@ class logger { static loglevel parse_verbosity(const string& name, loglevel fallback = loglevel::NONE); - void verbosity(loglevel&& level); + void verbosity(loglevel level); #ifdef DEBUG_LOGGER // {{{ template - void trace(string message, Args... args) const { - output(loglevel::TRACE, message, args...); + void trace(const string& message, Args&&... args) const { + output(loglevel::TRACE, message, std::forward(args)...); } #ifdef DEBUG_LOGGER_VERBOSE template - void trace_x(string message, Args... args) const { - output(loglevel::TRACE, message, args...); + void trace_x(const string& message, Args&&... args) const { + output(loglevel::TRACE, message, std::forward(args)...); } #else template - void trace_x(Args...) const {} + void trace_x(Args&&...) const {} #endif #else template - void trace(Args...) const {} + void trace(Args&&...) const {} template - void trace_x(Args...) const {} + void trace_x(Args&&...) const {} #endif // }}} /** * Output an info message */ template - void info(string message, Args... args) const { - output(loglevel::INFO, message, args...); + void info(const string& message, Args&&... args) const { + output(loglevel::INFO, message, std::forward(args)...); } /** * Output a warning message */ template - void warn(string message, Args... args) const { - output(loglevel::WARNING, message, args...); + void warn(const string& message, Args&&... args) const { + output(loglevel::WARNING, message, std::forward(args)...); } /** * Output an error message */ template - void err(string message, Args... args) const { - output(loglevel::ERROR, message, args...); + void err(const string& message, Args&&... args) const { + output(loglevel::ERROR, message, std::forward(args)...); } protected: @@ -95,14 +96,14 @@ class logger { /** * Convert thread id */ - size_t convert(const std::thread::id arg) const; + size_t convert(std::thread::id arg) const; /** * Write the log message to the output channel * if the defined verbosity level allows it */ template - void output(loglevel level, string format, Args... values) const { + void output(loglevel level, const string& format, Args&&... values) const { if (level > m_level) { return; } diff --git a/src/components/logger.cpp b/src/components/logger.cpp index 942e02fd..30913540 100644 --- a/src/components/logger.cpp +++ b/src/components/logger.cpp @@ -60,13 +60,13 @@ logger::logger(loglevel level) : m_level(level) { /** * Set output verbosity */ -void logger::verbosity(loglevel&& level) { +void logger::verbosity(loglevel level) { #ifndef DEBUG_LOGGER if (level == loglevel::TRACE) { throw application_error("Trace logging is not enabled..."); } #endif - m_level = forward(level); + m_level = level; } /** diff --git a/src/modules/fs.cpp b/src/modules/fs.cpp index 62d545f4..293def01 100644 --- a/src/modules/fs.cpp +++ b/src/modules/fs.cpp @@ -56,7 +56,7 @@ namespace modules { // Warn about "unreachable" format tag if (m_formatter->has(TAG_LABEL_UNMOUNTED) && m_remove_unmounted) { m_log.warn("%s: Defined format tag \"%s\" will never be used (reason: `remove-unmounted = true`)", name(), - TAG_LABEL_UNMOUNTED); + string{TAG_LABEL_UNMOUNTED}); } }