mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
cleanup _newestEntryAtIndex calc in RBH insert
This commit is contained in:
parent
16e7b2625b
commit
893e1864fd
1 changed files with 4 additions and 4 deletions
|
@ -21,7 +21,7 @@ template <typename T>
|
|||
class RingBufferHistory {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
RingBufferHistory(int capacity = 10)
|
||||
: _size(capacity + 1),
|
||||
_capacity(capacity),
|
||||
|
@ -45,7 +45,7 @@ public:
|
|||
|
||||
void insert(const T& entry) {
|
||||
// increment newest entry index cyclically
|
||||
_newestEntryAtIndex = (_newestEntryAtIndex == _size - 1) ? 0 : _newestEntryAtIndex + 1;
|
||||
_newestEntryAtIndex = (_newestEntryAtIndex + 1) % size;
|
||||
|
||||
// insert new entry
|
||||
_buffer[_newestEntryAtIndex] = entry;
|
||||
|
@ -53,12 +53,12 @@ public:
|
|||
_numEntries++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// std::unique_ptr need to be passed as an rvalue ref and moved into the vector
|
||||
void insert(T&& entry) {
|
||||
// increment newest entry index cyclically
|
||||
_newestEntryAtIndex = (_newestEntryAtIndex == _size - 1) ? 0 : _newestEntryAtIndex + 1;
|
||||
|
||||
|
||||
// insert new entry
|
||||
_buffer[_newestEntryAtIndex] = std::move(entry);
|
||||
if (_numEntries < _capacity) {
|
||||
|
|
Loading…
Reference in a new issue