Skip to content

Commit b711d72

Browse files
committed
Remove unnecessary friend class declarations of CowData.
Use default implementations for various containers.
1 parent 7b9c512 commit b711d72

File tree

5 files changed

+22
-38
lines changed

5 files changed

+22
-38
lines changed

core/string/ustring.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,9 @@ class Char16String {
171171
_FORCE_INLINE_ CharProxy<char16_t> operator[](int p_index) { return CharProxy<char16_t>(p_index, _cowdata); }
172172

173173
_FORCE_INLINE_ Char16String() {}
174-
_FORCE_INLINE_ Char16String(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
175-
_FORCE_INLINE_ Char16String(Char16String &&p_str) :
176-
_cowdata(std::move(p_str._cowdata)) {}
177-
_FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
174+
_FORCE_INLINE_ Char16String(const Char16String &p_str) = default;
175+
_FORCE_INLINE_ Char16String(Char16String &&p_str) = default;
176+
_FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata = p_str._cowdata; }
178177
_FORCE_INLINE_ void operator=(Char16String &&p_str) { _cowdata = std::move(p_str._cowdata); }
179178
_FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(p_cstr); }
180179

@@ -218,10 +217,9 @@ class CharString {
218217
_FORCE_INLINE_ CharProxy<char> operator[](int p_index) { return CharProxy<char>(p_index, _cowdata); }
219218

220219
_FORCE_INLINE_ CharString() {}
221-
_FORCE_INLINE_ CharString(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
222-
_FORCE_INLINE_ CharString(CharString &&p_str) :
223-
_cowdata(std::move(p_str._cowdata)) {}
224-
_FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
220+
_FORCE_INLINE_ CharString(const CharString &p_str) = default;
221+
_FORCE_INLINE_ CharString(CharString &&p_str) = default;
222+
_FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata = p_str._cowdata; }
225223
_FORCE_INLINE_ void operator=(CharString &&p_str) { _cowdata = std::move(p_str._cowdata); }
226224
_FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); }
227225

@@ -609,13 +607,12 @@ class String {
609607
*/
610608

611609
_FORCE_INLINE_ String() {}
612-
_FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
613-
_FORCE_INLINE_ String(String &&p_str) :
614-
_cowdata(std::move(p_str._cowdata)) {}
610+
_FORCE_INLINE_ String(const String &p_str) = default;
611+
_FORCE_INLINE_ String(String &&p_str) = default;
615612
#ifdef SIZE_EXTRA
616613
_NO_INLINE_ ~String() {}
617614
#endif
618-
_FORCE_INLINE_ void operator=(const String &p_str) { _cowdata._ref(p_str._cowdata); }
615+
_FORCE_INLINE_ void operator=(const String &p_str) { _cowdata = p_str._cowdata; }
619616
_FORCE_INLINE_ void operator=(String &&p_str) { _cowdata = std::move(p_str._cowdata); }
620617

621618
Vector<uint8_t> to_ascii_buffer() const;

core/templates/cowdata.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,12 @@
3939
#include <initializer_list>
4040
#include <type_traits>
4141

42-
template <typename T>
43-
class Vector;
44-
class String;
45-
class Char16String;
46-
class CharString;
47-
template <typename T, typename V>
48-
class VMap;
49-
5042
static_assert(std::is_trivially_destructible_v<std::atomic<uint64_t>>);
5143

5244
GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wplacement-new") // Silence a false positive warning (see GH-52119).
5345

5446
template <typename T>
5547
class CowData {
56-
template <typename TV>
57-
friend class Vector;
58-
friend class String;
59-
friend class Char16String;
60-
friend class CharString;
61-
template <typename TV, typename VV>
62-
friend class VMap;
63-
6448
public:
6549
typedef int64_t Size;
6650
typedef uint64_t USize;
@@ -129,11 +113,11 @@ class CowData {
129113
return (USize *)((uint8_t *)_ptr - DATA_OFFSET + SIZE_OFFSET);
130114
}
131115

132-
_FORCE_INLINE_ USize _get_alloc_size(USize p_elements) const {
116+
_FORCE_INLINE_ static USize _get_alloc_size(USize p_elements) {
133117
return next_po2(p_elements * sizeof(T));
134118
}
135119

136-
_FORCE_INLINE_ bool _get_alloc_size_checked(USize p_elements, USize *out) const {
120+
_FORCE_INLINE_ static bool _get_alloc_size_checked(USize p_elements, USize *out) {
137121
if (unlikely(p_elements == 0)) {
138122
*out = 0;
139123
return true;

core/templates/vector.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545

4646
#include <initializer_list>
4747

48+
template <typename T>
49+
class Vector;
50+
4851
template <typename T>
4952
class VectorWriteProxy {
5053
public:
@@ -167,7 +170,7 @@ class Vector {
167170
insert(i, p_val);
168171
}
169172

170-
void operator=(const Vector &p_from) { _cowdata._ref(p_from._cowdata); }
173+
void operator=(const Vector &p_from) { _cowdata = p_from._cowdata; }
171174
void operator=(Vector &&p_from) { _cowdata = std::move(p_from._cowdata); }
172175

173176
Vector<uint8_t> to_byte_array() const {
@@ -304,9 +307,8 @@ class Vector {
304307
_FORCE_INLINE_ Vector() {}
305308
_FORCE_INLINE_ Vector(std::initializer_list<T> p_init) :
306309
_cowdata(p_init) {}
307-
_FORCE_INLINE_ Vector(const Vector &p_from) { _cowdata._ref(p_from._cowdata); }
308-
_FORCE_INLINE_ Vector(Vector &&p_from) :
309-
_cowdata(std::move(p_from._cowdata)) {}
310+
_FORCE_INLINE_ Vector(const Vector &p_from) = default;
311+
_FORCE_INLINE_ Vector(Vector &&p_from) = default;
310312

311313
_FORCE_INLINE_ ~Vector() {}
312314
};

core/templates/vmap.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ class VMap {
195195
_FORCE_INLINE_ VMap() {}
196196
_FORCE_INLINE_ VMap(std::initializer_list<T> p_init) :
197197
_cowdata(p_init) {}
198-
_FORCE_INLINE_ VMap(const VMap &p_from) { _cowdata._ref(p_from._cowdata); }
198+
_FORCE_INLINE_ VMap(const VMap &p_from) = default;
199199

200-
inline void operator=(const VMap &p_from) {
201-
_cowdata._ref(p_from._cowdata);
202-
}
200+
void operator=(const VMap &p_from) { _cowdata = p_from._cowdata; }
203201
};

scene/resources/visual_shader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
class VisualShaderNodeParameter;
3939
class VisualShaderNode;
4040

41+
template <typename T, typename V>
42+
class VMap;
43+
4144
class VisualShader : public Shader {
4245
GDCLASS(VisualShader, Shader);
4346

0 commit comments

Comments
 (0)