From 4062add8edd5c8f7c180fa78a508e7d898cfbb11 Mon Sep 17 00:00:00 2001 From: Sahan Fernando Date: Thu, 3 Dec 2020 22:44:00 +1100 Subject: [PATCH] LibGUI: Optimize GUI::Variant move constructor --- Libraries/LibGUI/Variant.cpp | 13 ++++++++++--- Libraries/LibGUI/Variant.h | 1 + 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 #include +#include #include 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;