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

Remove unnecessary friend class declarations of CowData.

Use default implementations for various containers.
This commit is contained in:
Lukas Tenbrink
2024-12-20 13:22:46 +01:00
parent 7b9c5122fa
commit b711d72e8f
5 changed files with 22 additions and 38 deletions

View File

@@ -171,10 +171,9 @@ public:
_FORCE_INLINE_ CharProxy<char16_t> operator[](int p_index) { return CharProxy<char16_t>(p_index, _cowdata); } _FORCE_INLINE_ CharProxy<char16_t> operator[](int p_index) { return CharProxy<char16_t>(p_index, _cowdata); }
_FORCE_INLINE_ Char16String() {} _FORCE_INLINE_ Char16String() {}
_FORCE_INLINE_ Char16String(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); } _FORCE_INLINE_ Char16String(const Char16String &p_str) = default;
_FORCE_INLINE_ Char16String(Char16String &&p_str) : _FORCE_INLINE_ Char16String(Char16String &&p_str) = default;
_cowdata(std::move(p_str._cowdata)) {} _FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata = 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_ void operator=(Char16String &&p_str) { _cowdata = std::move(p_str._cowdata); }
_FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(p_cstr); } _FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(p_cstr); }
@@ -218,10 +217,9 @@ public:
_FORCE_INLINE_ CharProxy<char> operator[](int p_index) { return CharProxy<char>(p_index, _cowdata); } _FORCE_INLINE_ CharProxy<char> operator[](int p_index) { return CharProxy<char>(p_index, _cowdata); }
_FORCE_INLINE_ CharString() {} _FORCE_INLINE_ CharString() {}
_FORCE_INLINE_ CharString(const CharString &p_str) { _cowdata._ref(p_str._cowdata); } _FORCE_INLINE_ CharString(const CharString &p_str) = default;
_FORCE_INLINE_ CharString(CharString &&p_str) : _FORCE_INLINE_ CharString(CharString &&p_str) = default;
_cowdata(std::move(p_str._cowdata)) {} _FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata = 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_ void operator=(CharString &&p_str) { _cowdata = std::move(p_str._cowdata); }
_FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); } _FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); }
@@ -609,13 +607,12 @@ public:
*/ */
_FORCE_INLINE_ String() {} _FORCE_INLINE_ String() {}
_FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); } _FORCE_INLINE_ String(const String &p_str) = default;
_FORCE_INLINE_ String(String &&p_str) : _FORCE_INLINE_ String(String &&p_str) = default;
_cowdata(std::move(p_str._cowdata)) {}
#ifdef SIZE_EXTRA #ifdef SIZE_EXTRA
_NO_INLINE_ ~String() {} _NO_INLINE_ ~String() {}
#endif #endif
_FORCE_INLINE_ void operator=(const String &p_str) { _cowdata._ref(p_str._cowdata); } _FORCE_INLINE_ void operator=(const String &p_str) { _cowdata = p_str._cowdata; }
_FORCE_INLINE_ void operator=(String &&p_str) { _cowdata = std::move(p_str._cowdata); } _FORCE_INLINE_ void operator=(String &&p_str) { _cowdata = std::move(p_str._cowdata); }
Vector<uint8_t> to_ascii_buffer() const; Vector<uint8_t> to_ascii_buffer() const;

View File

@@ -39,28 +39,12 @@
#include <initializer_list> #include <initializer_list>
#include <type_traits> #include <type_traits>
template <typename T>
class Vector;
class String;
class Char16String;
class CharString;
template <typename T, typename V>
class VMap;
static_assert(std::is_trivially_destructible_v<std::atomic<uint64_t>>); static_assert(std::is_trivially_destructible_v<std::atomic<uint64_t>>);
GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wplacement-new") // Silence a false positive warning (see GH-52119). GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wplacement-new") // Silence a false positive warning (see GH-52119).
template <typename T> template <typename T>
class CowData { class CowData {
template <typename TV>
friend class Vector;
friend class String;
friend class Char16String;
friend class CharString;
template <typename TV, typename VV>
friend class VMap;
public: public:
typedef int64_t Size; typedef int64_t Size;
typedef uint64_t USize; typedef uint64_t USize;
@@ -129,11 +113,11 @@ private:
return (USize *)((uint8_t *)_ptr - DATA_OFFSET + SIZE_OFFSET); return (USize *)((uint8_t *)_ptr - DATA_OFFSET + SIZE_OFFSET);
} }
_FORCE_INLINE_ USize _get_alloc_size(USize p_elements) const { _FORCE_INLINE_ static USize _get_alloc_size(USize p_elements) {
return next_po2(p_elements * sizeof(T)); return next_po2(p_elements * sizeof(T));
} }
_FORCE_INLINE_ bool _get_alloc_size_checked(USize p_elements, USize *out) const { _FORCE_INLINE_ static bool _get_alloc_size_checked(USize p_elements, USize *out) {
if (unlikely(p_elements == 0)) { if (unlikely(p_elements == 0)) {
*out = 0; *out = 0;
return true; return true;

View File

@@ -45,6 +45,9 @@
#include <initializer_list> #include <initializer_list>
template <typename T>
class Vector;
template <typename T> template <typename T>
class VectorWriteProxy { class VectorWriteProxy {
public: public:
@@ -167,7 +170,7 @@ public:
insert(i, p_val); insert(i, p_val);
} }
void operator=(const Vector &p_from) { _cowdata._ref(p_from._cowdata); } void operator=(const Vector &p_from) { _cowdata = p_from._cowdata; }
void operator=(Vector &&p_from) { _cowdata = std::move(p_from._cowdata); } void operator=(Vector &&p_from) { _cowdata = std::move(p_from._cowdata); }
Vector<uint8_t> to_byte_array() const { Vector<uint8_t> to_byte_array() const {
@@ -304,9 +307,8 @@ public:
_FORCE_INLINE_ Vector() {} _FORCE_INLINE_ Vector() {}
_FORCE_INLINE_ Vector(std::initializer_list<T> p_init) : _FORCE_INLINE_ Vector(std::initializer_list<T> p_init) :
_cowdata(p_init) {} _cowdata(p_init) {}
_FORCE_INLINE_ Vector(const Vector &p_from) { _cowdata._ref(p_from._cowdata); } _FORCE_INLINE_ Vector(const Vector &p_from) = default;
_FORCE_INLINE_ Vector(Vector &&p_from) : _FORCE_INLINE_ Vector(Vector &&p_from) = default;
_cowdata(std::move(p_from._cowdata)) {}
_FORCE_INLINE_ ~Vector() {} _FORCE_INLINE_ ~Vector() {}
}; };

View File

@@ -195,9 +195,7 @@ public:
_FORCE_INLINE_ VMap() {} _FORCE_INLINE_ VMap() {}
_FORCE_INLINE_ VMap(std::initializer_list<T> p_init) : _FORCE_INLINE_ VMap(std::initializer_list<T> p_init) :
_cowdata(p_init) {} _cowdata(p_init) {}
_FORCE_INLINE_ VMap(const VMap &p_from) { _cowdata._ref(p_from._cowdata); } _FORCE_INLINE_ VMap(const VMap &p_from) = default;
inline void operator=(const VMap &p_from) { void operator=(const VMap &p_from) { _cowdata = p_from._cowdata; }
_cowdata._ref(p_from._cowdata);
}
}; };

View File

@@ -38,6 +38,9 @@
class VisualShaderNodeParameter; class VisualShaderNodeParameter;
class VisualShaderNode; class VisualShaderNode;
template <typename T, typename V>
class VMap;
class VisualShader : public Shader { class VisualShader : public Shader {
GDCLASS(VisualShader, Shader); GDCLASS(VisualShader, Shader);