From 28d6cf859ab851ba621b3c8dbab42e9bbd3300f9 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Wed, 26 Mar 2025 15:23:38 +0100 Subject: [PATCH] Add move semantics to `Ref`. --- core/object/ref_counted.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index 7bb15d9eea..5b330fe4ac 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -127,6 +127,15 @@ public: ref(p_from); } + void operator=(Ref &&p_from) { + if (reference == p_from.reference) { + return; + } + unref(); + reference = p_from.reference; + p_from.reference = nullptr; + } + template void operator=(const Ref &p_from) { ref_pointer(Object::cast_to(p_from.ptr())); @@ -159,6 +168,11 @@ public: this->operator=(p_from); } + Ref(Ref &&p_from) { + reference = p_from.reference; + p_from.reference = nullptr; + } + template Ref(const Ref &p_from) { this->operator=(p_from);