Skip to content

Commit f704113

Browse files
committed
Merge pull request #104649 from Ivorforce/move-semantics-ref-array-dict
Add move semantics to `Ref`
2 parents 19afe67 + 28d6cf8 commit f704113

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/object/ref_counted.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ class Ref {
127127
ref(p_from);
128128
}
129129

130+
void operator=(Ref &&p_from) {
131+
if (reference == p_from.reference) {
132+
return;
133+
}
134+
unref();
135+
reference = p_from.reference;
136+
p_from.reference = nullptr;
137+
}
138+
130139
template <typename T_Other>
131140
void operator=(const Ref<T_Other> &p_from) {
132141
ref_pointer<false>(Object::cast_to<T>(p_from.ptr()));
@@ -159,6 +168,11 @@ class Ref {
159168
this->operator=(p_from);
160169
}
161170

171+
Ref(Ref &&p_from) {
172+
reference = p_from.reference;
173+
p_from.reference = nullptr;
174+
}
175+
162176
template <typename T_Other>
163177
Ref(const Ref<T_Other> &p_from) {
164178
this->operator=(p_from);

0 commit comments

Comments
 (0)