1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Avoid copy-on-write when reading vectors

This commit is contained in:
mashumafi
2024-06-18 17:12:23 -04:00
committed by Lukas Tenbrink
parent 0793c626d2
commit b73346ef19
2 changed files with 4 additions and 3 deletions

View File

@@ -315,8 +315,8 @@ public:
template <typename T>
void Vector<T>::reverse() {
for (Size i = 0; i < size() / 2; i++) {
T *p = ptrw();
for (Size i = 0; i < size() / 2; i++) {
SWAP(p[i], p[size() - i - 1]);
}
}
@@ -329,8 +329,9 @@ void Vector<T>::append_array(Vector<T> p_other) {
}
const Size bs = size();
resize(bs + ds);
T *p = ptrw();
for (Size i = 0; i < ds; ++i) {
ptrw()[bs + i] = p_other[i];
p[bs + i] = p_other[i];
}
}

View File

@@ -738,7 +738,7 @@ int Array::bsearch(const Variant &p_value, bool p_before) const {
Variant value = p_value;
ERR_FAIL_COND_V(!_p->typed.validate(value, "binary search"), -1);
SearchArray<Variant, _ArrayVariantSort> avs;
return avs.bisect(_p->array.ptrw(), _p->array.size(), value, p_before);
return avs.bisect(_p->array.ptr(), _p->array.size(), value, p_before);
}
int Array::bsearch_custom(const Variant &p_value, const Callable &p_callable, bool p_before) const {