summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorSahan Fernando <sahan.h.fernando@gmail.com>2020-12-03 22:44:00 +1100
committerAndreas Kling <kling@serenityos.org>2020-12-03 21:53:29 +0100
commit4062add8edd5c8f7c180fa78a508e7d898cfbb11 (patch)
tree7f2f477b989e91cbd4641800a28041bd7481a331 /Libraries
parentd0812e9019706ebb380a66f056f707962ea42dde (diff)
downloadserenity-4062add8edd5c8f7c180fa78a508e7d898cfbb11.zip
LibGUI: Optimize GUI::Variant move constructor
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/Variant.cpp13
-rw-r--r--Libraries/LibGUI/Variant.h1
2 files changed, 11 insertions, 3 deletions
diff --git a/Libraries/LibGUI/Variant.cpp b/Libraries/LibGUI/Variant.cpp
index 3862870ddd..bd732f0130 100644
--- a/Libraries/LibGUI/Variant.cpp
+++ b/Libraries/LibGUI/Variant.cpp
@@ -26,6 +26,7 @@
#include <AK/FlyString.h>
#include <AK/JsonValue.h>
+#include <AK/RefPtr.h>
#include <LibGUI/Variant.h>
namespace GUI {
@@ -255,10 +256,8 @@ Variant& Variant::operator=(Variant&& other)
{
if (&other == this)
return *this;
- // FIXME: Move, not copy!
clear();
- copy_from(other);
- other.clear();
+ move_from(AK::move(other));
return *this;
}
@@ -267,6 +266,14 @@ Variant::Variant(const Variant& other)
copy_from(other);
}
+void Variant::move_from(Variant&& other)
+{
+ m_type = other.m_type;
+ m_value = other.m_value;
+ other.m_type = Type::Invalid;
+ other.m_value.as_string = nullptr;
+}
+
void Variant::copy_from(const Variant& other)
{
ASSERT(!is_valid());
diff --git a/Libraries/LibGUI/Variant.h b/Libraries/LibGUI/Variant.h
index 6e657e75f9..a04f7b2e17 100644
--- a/Libraries/LibGUI/Variant.h
+++ b/Libraries/LibGUI/Variant.h
@@ -250,6 +250,7 @@ public:
private:
void copy_from(const Variant&);
+ void move_from(Variant&&);
struct RawPoint {
int x;