From c8a8464f7d8b81bc60f3f227bdd76b6e8e21d073 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 12 Sep 2018 06:17:13 -0700 Subject: [PATCH] Optimize buffer construction --- include/fmt/core.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index aec66c44..b904e68e 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -365,6 +365,9 @@ class basic_buffer { std::size_t capacity_; protected: + // Don't initialize ptr_ since it is not accessed to save a few cycles. + basic_buffer(std::size_t sz) FMT_NOEXCEPT: size_(sz), capacity_(sz) {} + basic_buffer(T *p = FMT_NULL, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT: ptr_(p), size_(sz), capacity_(cap) {} @@ -445,8 +448,7 @@ class container_buffer : public basic_buffer { public: explicit container_buffer(Container &c) - : basic_buffer(&c[0], c.size(), c.size()), - container_(c) {} + : basic_buffer(c.size()), container_(c) {} }; struct error_handler {