Optmize set_formatter to avoid redundant clone

pull/1105/head
gabime 6 years ago
parent 03f0e2196e
commit e03c160e27

@ -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)
{
if (std::next(it) == sinks_.end())
{
// last element - we can be move it.
(*it)->set_formatter(std::move(f));
}
else
{ {
sink->set_formatter(f->clone()); (*it)->set_formatter(f->clone());
}
} }
} }

Loading…
Cancel
Save