Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2021-09-20 11:39:25 +0300
committerHannah von Reth <vonreth@kde.org>2021-09-21 12:03:56 +0300
commit4139d5ca60f3cc3d3353c8b3fcf7e59ca80ba31c (patch)
tree0788831524191a7a81470bd6d34841fcc7cb34f3 /src/common
parentedc0cce712cf05d872d41161184a511fff022f2a (diff)
Allow up to 20000 sync issues
Diffstat (limited to 'src/common')
-rw-r--r--src/common/fixedsizeringbuffer.h21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/common/fixedsizeringbuffer.h b/src/common/fixedsizeringbuffer.h
index 085f98b47..a82f4cdd8 100644
--- a/src/common/fixedsizeringbuffer.h
+++ b/src/common/fixedsizeringbuffer.h
@@ -24,20 +24,23 @@ namespace OCC {
/**
* A Fixed sized ring buffer optimized on continouous insertion
*/
-template <typename TYPE, size_t _Size>
+template <typename TYPE>
class FixedSizeRingBuffer
{
public:
- FixedSizeRingBuffer() = default;
+ FixedSizeRingBuffer(size_t size)
+ : _data(size, TYPE())
+ {
+ }
constexpr size_t capacity() const
{
- return _Size;
+ return _data.size();
}
constexpr bool isFull() const
{
- return size() >= _Size;
+ return size() >= _data.size();
}
constexpr size_t size() const
@@ -79,7 +82,7 @@ public:
Q_ASSERT(_start < _end);
// adjust offset to prevent overflow
const auto s = size();
- _start %= _Size;
+ _start %= _data.size();
_end = _start + s;
}
@@ -102,7 +105,7 @@ public:
void remove_if(const std::function<bool(const TYPE &)> &f)
{
// filter and sort the data
- FixedSizeRingBuffer<TYPE, _Size> tmp;
+ FixedSizeRingBuffer<TYPE> tmp(_data.size());
const auto start = convertToIndex(0);
for (auto it = begin() + start; it != end(); ++it) {
if (!f(*it)) {
@@ -119,14 +122,14 @@ public:
void reset(std::vector<TYPE> &&data)
{
- Q_ASSERT(data.size() <= _Size);
+ Q_ASSERT(data.size() <= _data.size());
_start = 0;
_end = data.size();
std::move(data.begin(), data.end(), _data.begin());
}
private:
- std::array<TYPE, _Size> _data;
+ std::vector<TYPE> _data;
// the sliding window of the ring buffer
size_t _start = 0;
@@ -135,7 +138,7 @@ private:
// converts an array index to the underlying array index
constexpr size_t convertToIndex(size_t i) const
{
- return (_start + i) % _Size;
+ return (_start + i) % _data.size();
}
};