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(
const std::function<void()>& worker_warmup_cb,
const std::chrono::milliseconds& flush_interval_ms,
const std::function<void()>& worker_teardown_cb):
_formatter(formatter),
_formatter(std::move(formatter)),
_sinks(sinks),
_q(queue_size),
_err_handler(err_handler),
_err_handler(std::move(err_handler)),
_flush_requested(false),
_terminate_requested(false),
_overflow_policy(overflow_policy),
......@@ -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)
{
_formatter = msg_formatter;
_formatter = std::move(msg_formatter);
}
// 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)
{
......@@ -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)
{
_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,
const std::function<void()>& worker_teardown_cb) :
async_logger(logger_name,
{
single_sink
std::move(single_sink)
}, 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
inline spdlog::logger::logger(const std::string& logger_name, spdlog::sink_ptr single_sink):
logger(logger_name,
{
single_sink
std::move(single_sink)
})
{}
......@@ -49,7 +49,7 @@ inline spdlog::logger::~logger() = default;
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)
......@@ -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)
{
_err_handler = err_handler;
_err_handler = std::move(err_handler);
}
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;
}
inline void spdlog::logger::flush_on(level::level_enum log_level)
{
_flush_level.store(log_level);
......@@ -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);
}
inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter)
{
_formatter = msg_formatter;
_formatter = std::move(msg_formatter);
}
inline void spdlog::logger::flush()
......
......@@ -34,7 +34,7 @@
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)
......@@ -183,13 +183,11 @@ inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_
}
//Create logger with multiple 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);
}
template <typename Sink, typename... 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_
return details::registry::instance().create(logger_name, { sink });
}
template<class It>
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
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)
......@@ -244,10 +241,9 @@ inline void spdlog::flush_on(level::level_enum log_level)
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)
{
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()
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()
......
#include "includes.h"
// 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;
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
oss_logger.info(msg);
return oss.str();
}
TEST_CASE("custom eol", "[pattern_formatter]")
{
std::string msg = "Hello custom eol test";
......@@ -38,7 +39,6 @@ TEST_CASE("level", "[pattern_formatter]")
REQUIRE(log_to_str("Some message", formatter) == "[info] Some message\n");
}
TEST_CASE("short level", "[pattern_formatter]")
{
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]")
REQUIRE(log_to_str("Some message", formatter) == "[pattern_tester] Some message\n");
}
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 now_tm = spdlog::details::os::localtime();
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";
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