util/ForeignFifoBuffer: add "noexcept"
This commit is contained in:
parent
90de2c4bd6
commit
3bceed1b53
@ -61,19 +61,19 @@ protected:
|
|||||||
T *data;
|
T *data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit constexpr ForeignFifoBuffer(std::nullptr_t n)
|
explicit constexpr ForeignFifoBuffer(std::nullptr_t n) noexcept
|
||||||
:capacity(0), data(n) {}
|
:capacity(0), data(n) {}
|
||||||
|
|
||||||
constexpr ForeignFifoBuffer(T *_data, size_type _capacity)
|
constexpr ForeignFifoBuffer(T *_data, size_type _capacity) noexcept
|
||||||
:capacity(_capacity), data(_data) {}
|
:capacity(_capacity), data(_data) {}
|
||||||
|
|
||||||
ForeignFifoBuffer(ForeignFifoBuffer &&src)
|
ForeignFifoBuffer(ForeignFifoBuffer &&src) noexcept
|
||||||
:head(src.head), tail(src.tail),
|
:head(src.head), tail(src.tail),
|
||||||
capacity(src.capacity), data(src.data) {
|
capacity(src.capacity), data(src.data) {
|
||||||
src.SetNull();
|
src.SetNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
ForeignFifoBuffer &operator=(ForeignFifoBuffer &&src) {
|
ForeignFifoBuffer &operator=(ForeignFifoBuffer &&src) noexcept {
|
||||||
head = src.head;
|
head = src.head;
|
||||||
tail = src.tail;
|
tail = src.tail;
|
||||||
capacity = src.capacity;
|
capacity = src.capacity;
|
||||||
@ -82,36 +82,36 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Swap(ForeignFifoBuffer<T> &other) {
|
void Swap(ForeignFifoBuffer<T> &other) noexcept {
|
||||||
std::swap(head, other.head);
|
std::swap(head, other.head);
|
||||||
std::swap(tail, other.tail);
|
std::swap(tail, other.tail);
|
||||||
std::swap(capacity, other.capacity);
|
std::swap(capacity, other.capacity);
|
||||||
std::swap(data, other.data);
|
std::swap(data, other.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool IsNull() const {
|
constexpr bool IsNull() const noexcept {
|
||||||
return data == nullptr;
|
return data == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool IsDefined() const {
|
constexpr bool IsDefined() const noexcept {
|
||||||
return !IsNull();
|
return !IsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
T *GetBuffer() {
|
T *GetBuffer() noexcept {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_type GetCapacity() const {
|
constexpr size_type GetCapacity() const noexcept {
|
||||||
return capacity;
|
return capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNull() {
|
void SetNull() noexcept {
|
||||||
head = tail = 0;
|
head = tail = 0;
|
||||||
capacity = 0;
|
capacity = 0;
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetBuffer(T *_data, size_type _capacity) {
|
void SetBuffer(T *_data, size_type _capacity) noexcept {
|
||||||
assert(_data != nullptr);
|
assert(_data != nullptr);
|
||||||
assert(_capacity > 0);
|
assert(_capacity > 0);
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ public:
|
|||||||
data = _data;
|
data = _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveBuffer(T *new_data, size_type new_capacity) {
|
void MoveBuffer(T *new_data, size_type new_capacity) noexcept {
|
||||||
assert(new_capacity >= tail - head);
|
assert(new_capacity >= tail - head);
|
||||||
|
|
||||||
std::move(data + head, data + tail, new_data);
|
std::move(data + head, data + tail, new_data);
|
||||||
@ -130,15 +130,15 @@ public:
|
|||||||
head = 0;
|
head = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear() {
|
void Clear() noexcept {
|
||||||
head = tail = 0;
|
head = tail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool empty() const {
|
constexpr bool empty() const noexcept {
|
||||||
return head == tail;
|
return head == tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool IsFull() const {
|
constexpr bool IsFull() const noexcept {
|
||||||
return head == 0 && tail == capacity;
|
return head == 0 && tail == capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ public:
|
|||||||
* Prepares writing. Returns a buffer range which may be written.
|
* Prepares writing. Returns a buffer range which may be written.
|
||||||
* When you are finished, call Append().
|
* When you are finished, call Append().
|
||||||
*/
|
*/
|
||||||
Range Write() {
|
Range Write() noexcept {
|
||||||
if (empty())
|
if (empty())
|
||||||
Clear();
|
Clear();
|
||||||
else if (tail == capacity)
|
else if (tail == capacity)
|
||||||
@ -155,7 +155,7 @@ public:
|
|||||||
return Range(data + tail, capacity - tail);
|
return Range(data + tail, capacity - tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WantWrite(size_type n) {
|
bool WantWrite(size_type n) noexcept {
|
||||||
if (tail + n <= capacity)
|
if (tail + n <= capacity)
|
||||||
/* enough space after the tail */
|
/* enough space after the tail */
|
||||||
return true;
|
return true;
|
||||||
@ -174,7 +174,7 @@ public:
|
|||||||
* Expands the tail of the buffer, after data has been written to
|
* Expands the tail of the buffer, after data has been written to
|
||||||
* the buffer returned by Write().
|
* the buffer returned by Write().
|
||||||
*/
|
*/
|
||||||
void Append(size_type n) {
|
void Append(size_type n) noexcept {
|
||||||
assert(tail <= capacity);
|
assert(tail <= capacity);
|
||||||
assert(n <= capacity);
|
assert(n <= capacity);
|
||||||
assert(tail + n <= capacity);
|
assert(tail + n <= capacity);
|
||||||
@ -182,7 +182,7 @@ public:
|
|||||||
tail += n;
|
tail += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_type GetAvailable() const {
|
constexpr size_type GetAvailable() const noexcept {
|
||||||
return tail - head;
|
return tail - head;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,14 +190,14 @@ public:
|
|||||||
* Return a buffer range which may be read. The buffer pointer is
|
* Return a buffer range which may be read. The buffer pointer is
|
||||||
* writable, to allow modifications while parsing.
|
* writable, to allow modifications while parsing.
|
||||||
*/
|
*/
|
||||||
constexpr Range Read() const {
|
constexpr Range Read() const noexcept {
|
||||||
return Range(data + head, tail - head);
|
return Range(data + head, tail - head);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks a chunk as consumed.
|
* Marks a chunk as consumed.
|
||||||
*/
|
*/
|
||||||
void Consume(size_type n) {
|
void Consume(size_type n) noexcept {
|
||||||
assert(tail <= capacity);
|
assert(tail <= capacity);
|
||||||
assert(head <= tail);
|
assert(head <= tail);
|
||||||
assert(n <= tail);
|
assert(n <= tail);
|
||||||
@ -206,7 +206,7 @@ public:
|
|||||||
head += n;
|
head += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_type Read(pointer_type p, size_type n) {
|
size_type Read(pointer_type p, size_type n) noexcept {
|
||||||
auto range = Read();
|
auto range = Read();
|
||||||
if (n > range.size)
|
if (n > range.size)
|
||||||
n = range.size;
|
n = range.size;
|
||||||
@ -220,7 +220,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return the number of items moved
|
* @return the number of items moved
|
||||||
*/
|
*/
|
||||||
size_type MoveFrom(ForeignFifoBuffer<T> &src) {
|
size_type MoveFrom(ForeignFifoBuffer<T> &src) noexcept {
|
||||||
auto r = src.Read();
|
auto r = src.Read();
|
||||||
auto w = Write();
|
auto w = Write();
|
||||||
size_t n = std::min(r.size, w.size);
|
size_t n = std::min(r.size, w.size);
|
||||||
@ -232,7 +232,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Shift() {
|
void Shift() noexcept {
|
||||||
if (head == 0)
|
if (head == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user