PackedByteArray, Array slice end exclusive, rename subarray to slice

This commit is contained in:
Nathan Franke
2021-11-26 19:18:26 -06:00
parent b43281c8ab
commit dd30253cdc
20 changed files with 166 additions and 157 deletions

View File

@ -144,27 +144,28 @@ public:
return ret;
}
Vector<T> subarray(int p_from, int p_to) const {
if (p_from < 0) {
p_from = size() + p_from;
}
if (p_to < 0) {
p_to = size() + p_to;
Vector<T> slice(int p_begin, int p_end) const {
Vector<T> result;
if (p_end < 0) {
p_end += size() + 1;
}
ERR_FAIL_INDEX_V(p_from, size(), Vector<T>());
ERR_FAIL_INDEX_V(p_to, size(), Vector<T>());
ERR_FAIL_INDEX_V(p_begin, size(), result);
ERR_FAIL_INDEX_V(p_end, size() + 1, result);
Vector<T> slice;
int span = 1 + p_to - p_from;
slice.resize(span);
const T *r = ptr();
T *w = slice.ptrw();
for (int i = 0; i < span; ++i) {
w[i] = r[p_from + i];
ERR_FAIL_COND_V(p_begin > p_end, result);
int result_size = p_end - p_begin;
result.resize(result_size);
const T *const r = ptr();
T *const w = result.ptrw();
for (int i = 0; i < result_size; ++i) {
w[i] = r[p_begin + i];
}
return slice;
return result;
}
bool operator==(const Vector<T> &p_arr) const {