diff --git a/include/ircd/buffer/buffer.h b/include/ircd/buffer/buffer.h index 57d877e5e..f2565fa9e 100644 --- a/include/ircd/buffer/buffer.h +++ b/include/ircd/buffer/buffer.h @@ -38,7 +38,7 @@ namespace ircd::buffer struct mutable_buffer; struct window_buffer; template struct fixed_buffer; - template struct unique_buffer; + template struct unique_buffer; template struct shared_buffer; template using fixed_const_buffer = fixed_buffer; diff --git a/include/ircd/buffer/unique_buffer.h b/include/ircd/buffer/unique_buffer.h index 18565ec4f..bb4225926 100644 --- a/include/ircd/buffer/unique_buffer.h +++ b/include/ircd/buffer/unique_buffer.h @@ -18,16 +18,13 @@ namespace ircd::buffer /// Like unique_ptr, this template holds ownership of an allocated buffer /// -template +template struct ircd::buffer::unique_buffer :buffer { - static char *allocate(const size_t &size); - buffer release(); - unique_buffer(const size_t &size); + unique_buffer(const size_t &size, const size_t &align = 0); explicit unique_buffer(const buffer &); unique_buffer(); unique_buffer(unique_buffer &&) noexcept; @@ -37,18 +34,16 @@ struct ircd::buffer::unique_buffer ~unique_buffer() noexcept; }; -template -ircd::buffer::unique_buffer::unique_buffer() +template +ircd::buffer::unique_buffer::unique_buffer() :buffer { nullptr, nullptr } {} -template -ircd::buffer::unique_buffer::unique_buffer(const buffer &src) +template +ircd::buffer::unique_buffer::unique_buffer(const buffer &src) :unique_buffer { size(src) @@ -62,19 +57,18 @@ ircd::buffer::unique_buffer::unique_buffer(const buffer &src) copy(dst, src); } -template -ircd::buffer::unique_buffer::unique_buffer(const size_t &size) +template +ircd::buffer::unique_buffer::unique_buffer(const size_t &size, + const size_t &align) :buffer { - allocate(size), size + aligned_alloc(align, size).release(), size } { } -template -ircd::buffer::unique_buffer::unique_buffer(unique_buffer &&other) +template +ircd::buffer::unique_buffer::unique_buffer(unique_buffer &&other) noexcept :buffer { @@ -84,10 +78,9 @@ noexcept get<0>(other) = nullptr; } -template -ircd::buffer::unique_buffer & -ircd::buffer::unique_buffer::operator=(unique_buffer &&other) +template +ircd::buffer::unique_buffer & +ircd::buffer::unique_buffer::operator=(unique_buffer &&other) noexcept { this->~unique_buffer(); @@ -98,32 +91,22 @@ noexcept return *this; } -template -ircd::buffer::unique_buffer::~unique_buffer() +template +ircd::buffer::unique_buffer::~unique_buffer() noexcept { std::free(const_cast(data(*this))); } -template +template buffer -ircd::buffer::unique_buffer::release() +ircd::buffer::unique_buffer::release() { const buffer ret{static_cast(*this)}; static_cast(*this) = buffer{}; return ret; } -template -char * -ircd::buffer::unique_buffer::allocate(const size_t &size) -{ - return aligned_alloc(alignment, size).release(); -} - inline std::unique_ptr ircd::buffer::aligned_alloc(const size_t &align, const size_t &size)