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) {