Godot Engine – Multi-platform 2D and 3D game engine
Add `Span` constructor to `Vector`, to be able to delete faulty `LocalVector::operator Vector`.
Lukas Tenbrinke339d03747f1
diff --git a/core/templates/cowdata.h b/core/templates/cowdata.hindex ccb007a13ac..834b83f3020 100644--- a/core/templates/cowdata.h+++ b/core/templates/cowdata.h@@ -219,6 +219,7 @@ public:_FORCE_INLINE_ CowData() {}_FORCE_INLINE_ ~CowData() { _unref(); }_FORCE_INLINE_ CowData(std::initializer_list<T> p_init);+ _FORCE_INLINE_ explicit CowData(Span<T> p_span);_FORCE_INLINE_ CowData(const CowData<T> &p_from) { _ref(p_from); }_FORCE_INLINE_ CowData(CowData<T> &&p_from) {_ptr = p_from._ptr;@@ -577,6 +578,14 @@ CowData<T>::CowData(std::initializer_list<T> p_init) {*_get_size() = p_init.size();}+template <typename T>+CowData<T>::CowData(Span<T> p_span) {+ CRASH_COND(_alloc_exact(p_span.size()));++ copy_arr_placement(_ptr, p_span.begin(), p_span.size());+ *_get_size() = p_span.size();+}+GODOT_GCC_WARNING_POP// Zero-constructing CowData initializes _ptr to nullptr (and thus empty).diff --git a/core/templates/local_vector.h b/core/templates/local_vector.hindex a2498d8155f..32989fa0f46 100644--- a/core/templates/local_vector.h+++ b/core/templates/local_vector.h@@ -323,16 +323,6 @@ public:insert(i, p_val);}- explicit operator Vector<T>() const {- Vector<T> ret;- ret.resize(count);- T *w = ret.ptrw();- if (w) {- copy_arr_placement(w, data, count);- }- return ret;- }-Vector<uint8_t> to_byte_array() const { //useful to pass stuff to gpu or variantVector<uint8_t> ret;ret.resize(count * sizeof(T));diff --git a/core/templates/vector.h b/core/templates/vector.hindex d38771a79ef..34d6ce7b0ca 100644--- a/core/templates/vector.h+++ b/core/templates/vector.h@@ -322,6 +322,8 @@ public:_FORCE_INLINE_ Vector() {}_FORCE_INLINE_ Vector(std::initializer_list<T> p_init) :_cowdata(p_init) {}+ _FORCE_INLINE_ explicit Vector(Span<T> p_span) :+ _cowdata(p_span) {}_FORCE_INLINE_ Vector(const Vector &p_from) = default;_FORCE_INLINE_ Vector(Vector &&p_from) = default;};