util/ForeignFifoBuffer: pass std::span to constructor
This commit is contained in:
parent
c9c5e84119
commit
a7d41a99a1
|
@ -28,7 +28,7 @@ public:
|
||||||
* Allocate a buffer with the given capacity.
|
* Allocate a buffer with the given capacity.
|
||||||
*/
|
*/
|
||||||
explicit DynamicFifoBuffer(size_type _capacity) noexcept
|
explicit DynamicFifoBuffer(size_type _capacity) noexcept
|
||||||
:ForeignFifoBuffer<T>(new T[_capacity], _capacity) {}
|
:ForeignFifoBuffer<T>(std::span{new T[_capacity], _capacity}) {}
|
||||||
|
|
||||||
~DynamicFifoBuffer() noexcept {
|
~DynamicFifoBuffer() noexcept {
|
||||||
delete[] GetBuffer();
|
delete[] GetBuffer();
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
T *old_data = GetBuffer();
|
T *old_data = GetBuffer();
|
||||||
T *new_data = new T[new_capacity];
|
T *new_data = new T[new_capacity];
|
||||||
ForeignFifoBuffer<T>::MoveBuffer(new_data, new_capacity);
|
ForeignFifoBuffer<T>::MoveBuffer({new_data, new_capacity});
|
||||||
delete[] old_data;
|
delete[] old_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ public:
|
||||||
explicit constexpr ForeignFifoBuffer(std::nullptr_t) noexcept
|
explicit constexpr ForeignFifoBuffer(std::nullptr_t) noexcept
|
||||||
:buffer() {}
|
:buffer() {}
|
||||||
|
|
||||||
constexpr ForeignFifoBuffer(T *_data, size_type _capacity) noexcept
|
explicit constexpr ForeignFifoBuffer(Range _buffer) noexcept
|
||||||
:buffer(_data, _capacity) {}
|
:buffer(_buffer) {}
|
||||||
|
|
||||||
constexpr ForeignFifoBuffer(ForeignFifoBuffer &&src) noexcept
|
constexpr ForeignFifoBuffer(ForeignFifoBuffer &&src) noexcept
|
||||||
:buffer(src.buffer), head(src.head), tail(src.tail) {
|
:buffer(src.buffer), head(src.head), tail(src.tail) {
|
||||||
|
@ -83,20 +83,20 @@ public:
|
||||||
head = tail = 0;
|
head = tail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetBuffer(T *_data, size_type _capacity) noexcept {
|
void SetBuffer(Range _buffer) noexcept {
|
||||||
assert(_data != nullptr);
|
assert(_buffer.data() != nullptr);
|
||||||
assert(_capacity > 0);
|
assert(!_buffer.empty());
|
||||||
|
|
||||||
buffer = {_data, _capacity};
|
buffer = _buffer;
|
||||||
head = tail = 0;
|
head = tail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveBuffer(T *new_data, size_type new_capacity) noexcept {
|
void MoveBuffer(Range _buffer) noexcept {
|
||||||
const auto r = Read();
|
const auto r = Read();
|
||||||
assert(new_capacity >= r.size());
|
assert(_buffer.size() >= r.size());
|
||||||
std::move(r.begin(), r.end(), new_data);
|
std::move(r.begin(), r.end(), _buffer.begin());
|
||||||
|
|
||||||
buffer = {new_data, new_capacity};
|
buffer = _buffer;
|
||||||
tail -= head;
|
tail -= head;
|
||||||
head = 0;
|
head = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue