From 147bc45658ae8e03f58a91da123f68038fb6291e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 29 Jan 2015 21:18:30 +0900 Subject: [PATCH] nghttpx: Refactor memchunk a bit --- src/memchunk.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/memchunk.h b/src/memchunk.h index 05923fc9..9116d477 100644 --- a/src/memchunk.h +++ b/src/memchunk.h @@ -37,8 +37,12 @@ namespace nghttp2 { template struct Memchunk { - Memchunk() - : kprev(nullptr), next(nullptr), pos(begin), last(begin), end(begin + N) { + Memchunk(std::unique_ptr next_chunk) + : knext(std::move(next_chunk)), kprev(nullptr), next(nullptr), pos(begin), + last(begin), end(begin + N) { + if (knext) { + knext->kprev = this; + } } size_t len() const { return last - pos; } size_t left() const { return end - last; } @@ -63,15 +67,9 @@ template struct Pool { return m; } - auto m = util::make_unique(); - auto p = m.get(); - if (pool) { - m->knext = std::move(pool); - m->knext->kprev = m.get(); - } - pool = std::move(m); + pool = util::make_unique(std::move(pool)); poolsize += T::size; - return p; + return pool.get(); } void recycle(T *m) { if (freelist) {