1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-13 13:31:48 +00:00

Remove unneeded read_only check for Array const operator.

This commit is contained in:
Yufeng Ying
2025-03-12 06:46:34 +08:00
parent 4f0cbc9a58
commit 883ca56517
3 changed files with 6 additions and 20 deletions

View File

@@ -88,11 +88,11 @@ Array::Iterator Array::end() {
}
Array::ConstIterator Array::begin() const {
return ConstIterator(_p->array.ptr(), _p->read_only);
return ConstIterator(_p->array.ptr());
}
Array::ConstIterator Array::end() const {
return ConstIterator(_p->array.ptr() + _p->array.size(), _p->read_only);
return ConstIterator(_p->array.ptr() + _p->array.size());
}
Variant &Array::operator[](int p_idx) {
@@ -104,10 +104,6 @@ Variant &Array::operator[](int p_idx) {
}
const Variant &Array::operator[](int p_idx) const {
if (unlikely(_p->read_only)) {
*_p->read_only = _p->array[p_idx];
return *_p->read_only;
}
return _p->array[p_idx];
}

View File

@@ -56,21 +56,19 @@ public:
_FORCE_INLINE_ bool operator==(const ConstIterator &p_other) const { return element_ptr == p_other.element_ptr; }
_FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return element_ptr != p_other.element_ptr; }
_FORCE_INLINE_ ConstIterator(const Variant *p_element_ptr, Variant *p_read_only = nullptr) :
element_ptr(p_element_ptr), read_only(p_read_only) {}
_FORCE_INLINE_ ConstIterator(const Variant *p_element_ptr) :
element_ptr(p_element_ptr) {}
_FORCE_INLINE_ ConstIterator() {}
_FORCE_INLINE_ ConstIterator(const ConstIterator &p_other) :
element_ptr(p_other.element_ptr), read_only(p_other.read_only) {}
element_ptr(p_other.element_ptr) {}
_FORCE_INLINE_ ConstIterator &operator=(const ConstIterator &p_other) {
element_ptr = p_other.element_ptr;
read_only = p_other.read_only;
return *this;
}
private:
const Variant *element_ptr = nullptr;
Variant *read_only = nullptr;
};
struct Iterator {
@@ -96,7 +94,7 @@ public:
}
operator ConstIterator() const {
return ConstIterator(element_ptr, read_only);
return ConstIterator(element_ptr);
}
private:

View File

@@ -997,18 +997,10 @@ Array::Iterator &Array::Iterator::operator--() {
}
const Variant &Array::ConstIterator::operator*() const {
if (unlikely(read_only)) {
*read_only = *element_ptr;
return *read_only;
}
return *element_ptr;
}
const Variant *Array::ConstIterator::operator->() const {
if (unlikely(read_only)) {
*read_only = *element_ptr;
return read_only;
}
return element_ptr;
}