From b4dcd592d85438f328c5b41f1a591a2cfb7cd182 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 9 Jul 2018 15:10:24 +0300 Subject: [PATCH] faster reset of cached buffer --- include/spdlog/details/pattern_formatter.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index d372a337..2bf8ea3e 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -29,6 +29,16 @@ class flag_formatter public: virtual ~flag_formatter() = default; virtual void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) = 0; + +protected: + fmt::memory_buffer cached_buf_; + std::tm cached_tm_; + bool from_cache(const std::tm &tm_time, fmt::memory_buffer &dest) + { + + } + + }; /////////////////////////////////////////////////////////////////////// @@ -460,7 +470,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter // each second cache the header auto duration = msg.time.time_since_epoch(); auto seconds = std::chrono::duration_cast(duration).count(); - if (true || cached_header_.size() == 0 || cached_seconds_ts_ != seconds) + if (cached_header_.size() == 0 || cached_seconds_ts_ != seconds) { cached_header_.resize(0); cached_header_.push_back('[');