diff --git a/core/string/ustring.h b/core/string/ustring.h index ac4ace224928..594e1d362b1d 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -39,6 +39,8 @@ #include "core/typedefs.h" #include "core/variant/array.h" +#include + /*************************************************************************/ /* Utility Functions */ /*************************************************************************/ @@ -193,7 +195,10 @@ class Char16String { _FORCE_INLINE_ Char16String() {} _FORCE_INLINE_ Char16String(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); } + _FORCE_INLINE_ Char16String(Char16String &&p_str) : + _cowdata(std::move(p_str._cowdata)) {} _FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); } + _FORCE_INLINE_ void operator=(Char16String &&p_str) { _cowdata = std::move(p_str._cowdata); } _FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(p_cstr); } void operator=(const char16_t *p_cstr); @@ -235,7 +240,10 @@ class CharString { _FORCE_INLINE_ CharString() {} _FORCE_INLINE_ CharString(const CharString &p_str) { _cowdata._ref(p_str._cowdata); } + _FORCE_INLINE_ CharString(CharString &&p_str) : + _cowdata(std::move(p_str._cowdata)) {} _FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata._ref(p_str._cowdata); } + _FORCE_INLINE_ void operator=(CharString &&p_str) { _cowdata = std::move(p_str._cowdata); } _FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); } void operator=(const char *p_cstr); @@ -594,7 +602,10 @@ class String { _FORCE_INLINE_ String() {} _FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); } + _FORCE_INLINE_ String(String &&p_str) : + _cowdata(std::move(p_str._cowdata)) {} _FORCE_INLINE_ void operator=(const String &p_str) { _cowdata._ref(p_str._cowdata); } + _FORCE_INLINE_ void operator=(String &&p_str) { _cowdata = std::move(p_str._cowdata); } Vector to_ascii_buffer() const; Vector to_utf8_buffer() const; diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h index 5f260ee870b8..f87fa1ad8111 100644 --- a/core/templates/cowdata.h +++ b/core/templates/cowdata.h @@ -167,6 +167,15 @@ class CowData { public: void operator=(const CowData &p_from) { _ref(p_from); } + void operator=(CowData &&p_from) { + if (_ptr == p_from._ptr) { + return; + } + + _unref(); + _ptr = p_from._ptr; + p_from._ptr = nullptr; + } _FORCE_INLINE_ T *ptrw() { _copy_on_write(); @@ -241,7 +250,11 @@ class CowData { _FORCE_INLINE_ CowData() {} _FORCE_INLINE_ ~CowData(); - _FORCE_INLINE_ CowData(CowData &p_from) { _ref(p_from); } + _FORCE_INLINE_ CowData(const CowData &p_from) { _ref(p_from); } + _FORCE_INLINE_ CowData(CowData &&p_from) { + _ptr = p_from._ptr; + p_from._ptr = nullptr; + } }; template diff --git a/core/templates/vector.h b/core/templates/vector.h index 0fcca47bae05..32e1339e959f 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -47,6 +47,7 @@ #include #include +#include template class VectorWriteProxy { @@ -147,9 +148,8 @@ class Vector { insert(i, p_val); } - inline void operator=(const Vector &p_from) { - _cowdata._ref(p_from._cowdata); - } + void operator=(const Vector &p_from) { _cowdata._ref(p_from._cowdata); } + void operator=(Vector &&p_from) { _cowdata = std::move(p_from._cowdata); } Vector to_byte_array() const { Vector ret; @@ -290,6 +290,8 @@ class Vector { } } _FORCE_INLINE_ Vector(const Vector &p_from) { _cowdata._ref(p_from._cowdata); } + _FORCE_INLINE_ Vector(Vector &&p_from) : + _cowdata(std::move(p_from._cowdata)) {} _FORCE_INLINE_ ~Vector() {} };