summaryrefslogtreecommitdiff
path: root/core/ring_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/ring_buffer.h')
-rw-r--r--core/ring_buffer.h22
1 files changed, 9 insertions, 13 deletions
diff --git a/core/ring_buffer.h b/core/ring_buffer.h
index 620a3a3846..2fd622b86f 100644
--- a/core/ring_buffer.h
+++ b/core/ring_buffer.h
@@ -35,10 +35,9 @@
template <typename T>
class RingBuffer {
-
Vector<T> data;
- int read_pos;
- int write_pos;
+ int read_pos = 0;
+ int write_pos = 0;
int size_mask;
inline int inc(int &p_var, int p_size) const {
@@ -78,12 +77,12 @@ public:
};
int copy(T *p_buf, int p_offset, int p_size) const {
-
int left = data_left();
if ((p_offset + p_size) > left) {
p_size -= left - p_offset;
- if (p_size <= 0)
+ if (p_size <= 0) {
return 0;
+ }
}
p_size = MIN(left, p_size);
int pos = read_pos;
@@ -104,12 +103,12 @@ public:
};
int find(const T &t, int p_offset, int p_max_size) const {
-
int left = data_left();
if ((p_offset + p_max_size) > left) {
p_max_size -= left - p_offset;
- if (p_max_size <= 0)
+ if (p_max_size <= 0) {
return 0;
+ }
}
p_max_size = MIN(left, p_max_size);
int pos = read_pos;
@@ -120,8 +119,9 @@ public:
end = MIN(end, size());
int total = end - pos;
for (int i = 0; i < total; i++) {
- if (data[pos + i] == t)
+ if (data[pos + i] == t) {
return i + (p_max_size - to_read);
+ }
};
to_read -= total;
pos = 0;
@@ -148,7 +148,6 @@ public:
};
int write(const T *p_buf, int p_size) {
-
int left = space_left();
p_size = MIN(left, p_size);
@@ -156,7 +155,6 @@ public:
int to_write = p_size;
int src = 0;
while (to_write) {
-
int end = pos + to_write;
end = MIN(end, size());
int total = end - pos;
@@ -214,11 +212,9 @@ public:
};
RingBuffer<T>(int p_power = 0) {
- read_pos = 0;
- write_pos = 0;
resize(p_power);
};
- ~RingBuffer<T>(){};
+ ~RingBuffer<T>() {}
};
#endif // RING_BUFFER_H