nghttpx: Refactor memchunk a bit

This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-29 21:18:30 +09:00
parent 00555dc7bb
commit 147bc45658
1 changed files with 8 additions and 10 deletions

View File

@ -37,8 +37,12 @@
namespace nghttp2 { namespace nghttp2 {
template <size_t N> struct Memchunk { template <size_t N> struct Memchunk {
Memchunk() Memchunk(std::unique_ptr<Memchunk> next_chunk)
: kprev(nullptr), next(nullptr), pos(begin), last(begin), end(begin + N) { : 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 len() const { return last - pos; }
size_t left() const { return end - last; } size_t left() const { return end - last; }
@ -63,15 +67,9 @@ template <typename T> struct Pool {
return m; return m;
} }
auto m = util::make_unique<T>(); pool = util::make_unique<T>(std::move(pool));
auto p = m.get();
if (pool) {
m->knext = std::move(pool);
m->knext->kprev = m.get();
}
pool = std::move(m);
poolsize += T::size; poolsize += T::size;
return p; return pool.get();
} }
void recycle(T *m) { void recycle(T *m) {
if (freelist) { if (freelist) {