Commit e03c160e authored by gabime's avatar gabime

Optmize set_formatter to avoid redundant clone

parent 03f0e219
...@@ -64,13 +64,21 @@ SPDLOG_INLINE const std::string &logger::name() const ...@@ -64,13 +64,21 @@ SPDLOG_INLINE const std::string &logger::name() const
return name_; return name_;
} }
// set formatting for the sinks in this logger. // set formatting for the sinks in this logger. redundant
// each sink will get a seperate instance of the formatter object. // each sink will get a seperate instance of the formatter object.
SPDLOG_INLINE void logger::set_formatter(std::unique_ptr<formatter> f) SPDLOG_INLINE void logger::set_formatter(std::unique_ptr<formatter> f)
{ {
for (auto &sink : sinks_) for (auto it = sinks_.begin(); it != sinks_.end(); ++it)
{ {
sink->set_formatter(f->clone()); if (std::next(it) == sinks_.end())
{
// last element - we can be move it.
(*it)->set_formatter(std::move(f));
}
else
{
(*it)->set_formatter(f->clone());
}
} }
} }
......
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