PackedByteArray, Array slice end exclusive, rename subarray to slice
This commit is contained in:
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user