mirror of
https://github.com/matrix-construct/construct
synced 2024-12-01 19:22:53 +01:00
ircd::buffer: Add copy-from-buffer ctor to unique_buffer.
This commit is contained in:
parent
141f4e1c0a
commit
6f75a1c8f8
1 changed files with 31 additions and 9 deletions
|
@ -18,8 +18,9 @@ template<class buffer,
|
|||
struct ircd::buffer::unique_buffer
|
||||
:buffer
|
||||
{
|
||||
unique_buffer(std::unique_ptr<uint8_t[]> &&, const size_t &size);
|
||||
unique_buffer(const size_t &size);
|
||||
unique_buffer(std::unique_ptr<char[]> &&, const size_t &size);
|
||||
explicit unique_buffer(const buffer &);
|
||||
unique_buffer();
|
||||
unique_buffer(unique_buffer &&) noexcept;
|
||||
unique_buffer(const unique_buffer &) = delete;
|
||||
|
@ -39,26 +40,37 @@ ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer()
|
|||
|
||||
template<class buffer,
|
||||
uint alignment>
|
||||
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(std::unique_ptr<uint8_t[]> &&b,
|
||||
const size_t &size)
|
||||
:buffer
|
||||
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(const buffer &src)
|
||||
:buffer{[&src]() -> buffer
|
||||
{
|
||||
std::unique_ptr<char[]> ret
|
||||
{
|
||||
new __attribute__((aligned(16))) char[size(src)]
|
||||
};
|
||||
|
||||
const mutable_buffer dst
|
||||
{
|
||||
ret.get(), size(src)
|
||||
};
|
||||
|
||||
copy(dst, src);
|
||||
return dst;
|
||||
}()}
|
||||
{
|
||||
typename buffer::iterator(b.release()), size
|
||||
}
|
||||
{}
|
||||
|
||||
template<class buffer,
|
||||
uint alignment>
|
||||
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(const size_t &size)
|
||||
:unique_buffer<buffer, alignment>
|
||||
{
|
||||
std::unique_ptr<uint8_t[]>
|
||||
std::unique_ptr<char[]>
|
||||
{
|
||||
//TODO: Can't use a template parameter to the attribute even though
|
||||
// it's known at compile time. Hardcoding this until fixed with better
|
||||
// aligned dynamic memory.
|
||||
//new __attribute__((aligned(alignment))) uint8_t[size]
|
||||
new __attribute__((aligned(16))) uint8_t[size]
|
||||
//new __attribute__((aligned(alignment))) char[size]
|
||||
new __attribute__((aligned(16))) char[size]
|
||||
},
|
||||
size
|
||||
}
|
||||
|
@ -67,6 +79,16 @@ ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(const size_t &size
|
|||
assert(alignment == 16);
|
||||
}
|
||||
|
||||
template<class buffer,
|
||||
uint alignment>
|
||||
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(std::unique_ptr<char[]> &&b,
|
||||
const size_t &size)
|
||||
:buffer
|
||||
{
|
||||
typename buffer::iterator(b.release()), size
|
||||
}
|
||||
{}
|
||||
|
||||
template<class buffer,
|
||||
uint alignment>
|
||||
ircd::buffer::unique_buffer<buffer, alignment>::unique_buffer(unique_buffer &&other)
|
||||
|
|
Loading…
Reference in a new issue