Skip to content

Commit

Permalink
Use LocalVector instead of Vector in core templates
Browse files Browse the repository at this point in the history
  • Loading branch information
kus04e4ek committed Jun 16, 2024
1 parent 71699e0 commit 217b48d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
12 changes: 6 additions & 6 deletions core/templates/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
#ifndef RING_BUFFER_H
#define RING_BUFFER_H

#include "core/templates/vector.h"
#include "core/templates/local_vector.h"

template <typename T>
class RingBuffer {
Vector<T> data;
LocalVector<T> data;
int read_pos = 0;
int write_pos = 0;
int size_mask;
Expand All @@ -50,7 +50,7 @@ class RingBuffer {
public:
T read() {
ERR_FAIL_COND_V(space_left() < 1, T());
return data.ptr()[inc(read_pos, 1)];
return data[inc(read_pos, 1)];
}

int read(T *p_buf, int p_size, bool p_advance = true) {
Expand Down Expand Up @@ -143,7 +143,7 @@ class RingBuffer {

Error write(const T &p_v) {
ERR_FAIL_COND_V(space_left() < 1, FAILED);
data.write[inc(write_pos, 1)] = p_v;
data[inc(write_pos, 1)] = p_v;
return OK;
}

Expand All @@ -160,7 +160,7 @@ class RingBuffer {
int total = end - pos;

for (int i = 0; i < total; i++) {
data.write[pos + i] = p_buf[src++];
data[pos + i] = p_buf[src++];
}
to_write -= total;
pos = 0;
Expand Down Expand Up @@ -200,7 +200,7 @@ class RingBuffer {
data.resize(int64_t(1) << int64_t(p_power));
if (old_size < new_size && read_pos > write_pos) {
for (int i = 0; i < write_pos; i++) {
data.write[(old_size + i) & mask] = data[i];
data[(old_size + i) & mask] = data[i];
}
write_pos = (old_size + write_pos) & mask;
} else {
Expand Down
17 changes: 8 additions & 9 deletions core/templates/vset.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
#ifndef VSET_H
#define VSET_H

#include "core/templates/vector.h"
#include "core/typedefs.h"
#include "core/templates/local_vector.h"

template <typename T>
class VSet {
Vector<T> _data;
LocalVector<T> _data;

_FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const {
r_exact = false;
Expand All @@ -59,16 +58,16 @@ class VSet {
middle = (low + high) / 2;

if (p_val < a[middle]) {
high = middle - 1; //search low end of array
high = middle - 1; // Search the low end of the array.
} else if (a[middle] < p_val) {
low = middle + 1; //search high end of array
low = middle + 1; // Search the high end of the array.
} else {
r_exact = true;
return middle;
}
}

//return the position where this would be inserted
// Return the position where this would be inserted.
if (a[middle] < p_val) {
middle++;
}
Expand All @@ -89,9 +88,9 @@ class VSet {
middle = (low + high) / 2;

if (p_val < a[middle]) {
high = middle - 1; //search low end of array
high = middle - 1; // Search the low end of the array.
} else if (a[middle] < p_val) {
low = middle + 1; //search high end of array
low = middle + 1; // Search the high end of the array.
} else {
return middle;
}
Expand Down Expand Up @@ -131,7 +130,7 @@ class VSet {
_FORCE_INLINE_ int size() const { return _data.size(); }

inline T &operator[](int p_index) {
return _data.write[p_index];
return _data[p_index];
}

inline const T &operator[](int p_index) const {
Expand Down

0 comments on commit 217b48d

Please sign in to comment.