Commit 68f91822 authored by Daniel Chabrowski's avatar Daniel Chabrowski

performance-unnecessary-value-param

parent 7aed4985
...@@ -207,10 +207,10 @@ inline spdlog::details::async_log_helper::async_log_helper( ...@@ -207,10 +207,10 @@ inline spdlog::details::async_log_helper::async_log_helper(
const std::function<void()>& worker_warmup_cb, const std::function<void()>& worker_warmup_cb,
const std::chrono::milliseconds& flush_interval_ms, const std::chrono::milliseconds& flush_interval_ms,
const std::function<void()>& worker_teardown_cb): const std::function<void()>& worker_teardown_cb):
_formatter(formatter), _formatter(std::move(formatter)),
_sinks(sinks), _sinks(sinks),
_q(queue_size), _q(queue_size),
_err_handler(err_handler), _err_handler(std::move(err_handler)),
_flush_requested(false), _flush_requested(false),
_terminate_requested(false), _terminate_requested(false),
_overflow_policy(overflow_policy), _overflow_policy(overflow_policy),
...@@ -349,10 +349,9 @@ inline void spdlog::details::async_log_helper::handle_flush_interval(log_clock:: ...@@ -349,10 +349,9 @@ inline void spdlog::details::async_log_helper::handle_flush_interval(log_clock::
inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_formatter) inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_formatter)
{ {
_formatter = msg_formatter; _formatter = std::move(msg_formatter);
} }
// spin, yield or sleep. use the time passed since last message as a hint // spin, yield or sleep. use the time passed since last message as a hint
inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_clock::time_point& now, const spdlog::log_clock::time_point& last_op_time) inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_clock::time_point& now, const spdlog::log_clock::time_point& last_op_time)
{ {
...@@ -389,8 +388,5 @@ inline void spdlog::details::async_log_helper::wait_empty_q() ...@@ -389,8 +388,5 @@ inline void spdlog::details::async_log_helper::wait_empty_q()
inline void spdlog::details::async_log_helper::set_error_handler(spdlog::log_err_handler err_handler) inline void spdlog::details::async_log_helper::set_error_handler(spdlog::log_err_handler err_handler)
{ {
_err_handler = err_handler; _err_handler = std::move(err_handler);
} }
...@@ -48,7 +48,7 @@ inline spdlog::async_logger::async_logger(const std::string& logger_name, ...@@ -48,7 +48,7 @@ inline spdlog::async_logger::async_logger(const std::string& logger_name,
const std::function<void()>& worker_teardown_cb) : const std::function<void()>& worker_teardown_cb) :
async_logger(logger_name, async_logger(logger_name,
{ {
single_sink std::move(single_sink)
}, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb) {} }, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb) {}
......
...@@ -39,7 +39,7 @@ inline spdlog::logger::logger(const std::string& logger_name, sinks_init_list si ...@@ -39,7 +39,7 @@ inline spdlog::logger::logger(const std::string& logger_name, sinks_init_list si
inline spdlog::logger::logger(const std::string& logger_name, spdlog::sink_ptr single_sink): inline spdlog::logger::logger(const std::string& logger_name, spdlog::sink_ptr single_sink):
logger(logger_name, logger(logger_name,
{ {
single_sink std::move(single_sink)
}) })
{} {}
...@@ -49,7 +49,7 @@ inline spdlog::logger::~logger() = default; ...@@ -49,7 +49,7 @@ inline spdlog::logger::~logger() = default;
inline void spdlog::logger::set_formatter(spdlog::formatter_ptr msg_formatter) inline void spdlog::logger::set_formatter(spdlog::formatter_ptr msg_formatter)
{ {
_set_formatter(msg_formatter); _set_formatter(std::move(msg_formatter));
} }
inline void spdlog::logger::set_pattern(const std::string& pattern, pattern_time_type pattern_time) inline void spdlog::logger::set_pattern(const std::string& pattern, pattern_time_type pattern_time)
...@@ -281,7 +281,7 @@ inline void spdlog::logger::set_level(spdlog::level::level_enum log_level) ...@@ -281,7 +281,7 @@ inline void spdlog::logger::set_level(spdlog::level::level_enum log_level)
inline void spdlog::logger::set_error_handler(spdlog::log_err_handler err_handler) inline void spdlog::logger::set_error_handler(spdlog::log_err_handler err_handler)
{ {
_err_handler = err_handler; _err_handler = std::move(err_handler);
} }
inline spdlog::log_err_handler spdlog::logger::error_handler() inline spdlog::log_err_handler spdlog::logger::error_handler()
...@@ -289,7 +289,6 @@ inline spdlog::log_err_handler spdlog::logger::error_handler() ...@@ -289,7 +289,6 @@ inline spdlog::log_err_handler spdlog::logger::error_handler()
return _err_handler; return _err_handler;
} }
inline void spdlog::logger::flush_on(level::level_enum log_level) inline void spdlog::logger::flush_on(level::level_enum log_level)
{ {
_flush_level.store(log_level); _flush_level.store(log_level);
...@@ -330,9 +329,10 @@ inline void spdlog::logger::_set_pattern(const std::string& pattern, pattern_tim ...@@ -330,9 +329,10 @@ inline void spdlog::logger::_set_pattern(const std::string& pattern, pattern_tim
{ {
_formatter = std::make_shared<pattern_formatter>(pattern, pattern_time); _formatter = std::make_shared<pattern_formatter>(pattern, pattern_time);
} }
inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter) inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter)
{ {
_formatter = msg_formatter; _formatter = std::move(msg_formatter);
} }
inline void spdlog::logger::flush() inline void spdlog::logger::flush()
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
inline void spdlog::register_logger(std::shared_ptr<logger> logger) inline void spdlog::register_logger(std::shared_ptr<logger> logger)
{ {
return details::registry::instance().register_logger(logger); return details::registry::instance().register_logger(std::move(logger));
} }
inline std::shared_ptr<spdlog::logger> spdlog::get(const std::string& name) inline std::shared_ptr<spdlog::logger> spdlog::get(const std::string& name)
...@@ -183,13 +183,11 @@ inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_ ...@@ -183,13 +183,11 @@ inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_
} }
//Create logger with multiple sinks //Create logger with multiple sinks
inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, spdlog::sinks_init_list sinks) inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, spdlog::sinks_init_list sinks)
{ {
return details::registry::instance().create(logger_name, sinks); return details::registry::instance().create(logger_name, sinks);
} }
template <typename Sink, typename... Args> template <typename Sink, typename... Args>
inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, Args... args) inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, Args... args)
{ {
...@@ -197,7 +195,6 @@ inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_ ...@@ -197,7 +195,6 @@ inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_
return details::registry::instance().create(logger_name, { sink }); return details::registry::instance().create(logger_name, { sink });
} }
template<class It> template<class It>
inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end) inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end)
{ {
...@@ -224,7 +221,7 @@ inline std::shared_ptr<spdlog::logger> spdlog::create_async(const std::string& l ...@@ -224,7 +221,7 @@ inline std::shared_ptr<spdlog::logger> spdlog::create_async(const std::string& l
inline void spdlog::set_formatter(spdlog::formatter_ptr f) inline void spdlog::set_formatter(spdlog::formatter_ptr f)
{ {
details::registry::instance().formatter(f); details::registry::instance().formatter(std::move(f));
} }
inline void spdlog::set_pattern(const std::string& format_string) inline void spdlog::set_pattern(const std::string& format_string)
...@@ -244,10 +241,9 @@ inline void spdlog::flush_on(level::level_enum log_level) ...@@ -244,10 +241,9 @@ inline void spdlog::flush_on(level::level_enum log_level)
inline void spdlog::set_error_handler(log_err_handler handler) inline void spdlog::set_error_handler(log_err_handler handler)
{ {
return details::registry::instance().set_error_handler(handler); return details::registry::instance().set_error_handler(std::move(handler));
} }
inline void spdlog::set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy, const std::function<void()>& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function<void()>& worker_teardown_cb) inline void spdlog::set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy, const std::function<void()>& worker_warmup_cb, const std::chrono::milliseconds& flush_interval_ms, const std::function<void()>& worker_teardown_cb)
{ {
details::registry::instance().set_async_mode(queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb); details::registry::instance().set_async_mode(queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb);
...@@ -260,7 +256,7 @@ inline void spdlog::set_sync_mode() ...@@ -260,7 +256,7 @@ inline void spdlog::set_sync_mode()
inline void spdlog::apply_all(std::function<void(std::shared_ptr<logger>)> fun) inline void spdlog::apply_all(std::function<void(std::shared_ptr<logger>)> fun)
{ {
details::registry::instance().apply_all(fun); details::registry::instance().apply_all(std::move(fun));
} }
inline void spdlog::drop_all() inline void spdlog::drop_all()
......
#include "includes.h" #include "includes.h"
// log to str and return it // log to str and return it
static std::string log_to_str(const std::string& msg, std::shared_ptr<spdlog::formatter> formatter = nullptr) static std::string log_to_str(const std::string& msg, const std::shared_ptr<spdlog::formatter>& formatter = nullptr)
{ {
std::ostringstream oss; std::ostringstream oss;
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss); auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
...@@ -11,6 +11,7 @@ static std::string log_to_str(const std::string& msg, std::shared_ptr<spdlog::fo ...@@ -11,6 +11,7 @@ static std::string log_to_str(const std::string& msg, std::shared_ptr<spdlog::fo
oss_logger.info(msg); oss_logger.info(msg);
return oss.str(); return oss.str();
} }
TEST_CASE("custom eol", "[pattern_formatter]") TEST_CASE("custom eol", "[pattern_formatter]")
{ {
std::string msg = "Hello custom eol test"; std::string msg = "Hello custom eol test";
...@@ -38,7 +39,6 @@ TEST_CASE("level", "[pattern_formatter]") ...@@ -38,7 +39,6 @@ TEST_CASE("level", "[pattern_formatter]")
REQUIRE(log_to_str("Some message", formatter) == "[info] Some message\n"); REQUIRE(log_to_str("Some message", formatter) == "[info] Some message\n");
} }
TEST_CASE("short level", "[pattern_formatter]") TEST_CASE("short level", "[pattern_formatter]")
{ {
auto formatter = std::make_shared<spdlog::pattern_formatter>("[%L] %v", spdlog::pattern_time_type::local, "\n"); auto formatter = std::make_shared<spdlog::pattern_formatter>("[%L] %v", spdlog::pattern_time_type::local, "\n");
...@@ -51,19 +51,11 @@ TEST_CASE("name", "[pattern_formatter]") ...@@ -51,19 +51,11 @@ TEST_CASE("name", "[pattern_formatter]")
REQUIRE(log_to_str("Some message", formatter) == "[pattern_tester] Some message\n"); REQUIRE(log_to_str("Some message", formatter) == "[pattern_tester] Some message\n");
} }
TEST_CASE("date MM/DD/YY ", "[pattern_formatter]") TEST_CASE("date MM/DD/YY ", "[pattern_formatter]")
{ {
using namespace::std::chrono;
auto formatter = std::make_shared<spdlog::pattern_formatter>("%D %v", spdlog::pattern_time_type::local, "\n"); auto formatter = std::make_shared<spdlog::pattern_formatter>("%D %v", spdlog::pattern_time_type::local, "\n");
auto now_tm = spdlog::details::os::localtime(); auto now_tm = spdlog::details::os::localtime();
std::stringstream oss; std::stringstream oss;
oss << std::setfill('0') << std::setw(2) << now_tm.tm_mon + 1 << "/" << now_tm.tm_mday << "/" << (now_tm.tm_year + 1900) % 1000 << " Some message\n"; oss << std::setfill('0') << std::setw(2) << now_tm.tm_mon + 1 << "/" << now_tm.tm_mday << "/" << (now_tm.tm_year + 1900) % 1000 << " Some message\n";
REQUIRE(log_to_str("Some message", formatter) == oss.str()); REQUIRE(log_to_str("Some message", formatter) == oss.str());
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment