diff --git a/AK/AKString.h b/AK/AKString.h index 4f9b8ec84a..20ee499de2 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -39,6 +39,11 @@ public: { } + String(const StringImpl* impl) + : m_impl(const_cast(impl)) + { + } + String(RetainPtr&& impl) : m_impl(move(impl)) { diff --git a/LibGUI/GVariant.cpp b/LibGUI/GVariant.cpp index 958d66ad38..196249d8a0 100644 --- a/LibGUI/GVariant.cpp +++ b/LibGUI/GVariant.cpp @@ -6,6 +6,11 @@ GVariant::GVariant() } GVariant::~GVariant() +{ + clear(); +} + +void GVariant::clear() { switch (m_type) { case Type::String: @@ -20,6 +25,8 @@ GVariant::~GVariant() default: break; } + m_type = Type::Invalid; + m_value.as_string = nullptr; } GVariant::GVariant(int value) @@ -85,9 +92,24 @@ GVariant::GVariant(const Rect& rect) m_value.as_rect = (const RawRect&)rect; } -GVariant::GVariant(const GVariant& other) - : m_type(other.m_type) +GVariant& GVariant::operator=(const GVariant& other) { + if (&other == this) + return *this; + clear(); + copy_from(other); + return *this; +} + +GVariant::GVariant(const GVariant& other) +{ + copy_from(other); +} + +void GVariant::copy_from(const GVariant& other) +{ + ASSERT(!is_valid()); + m_type = other.m_type; switch (m_type) { case Type::Bool: m_value.as_bool = other.m_value.as_bool; @@ -214,6 +236,7 @@ String GVariant::to_string() const case Type::Rect: return as_rect().to_string(); case Type::Invalid: + return "[Null]"; break; } ASSERT_NOT_REACHED(); diff --git a/LibGUI/GVariant.h b/LibGUI/GVariant.h index 83a97008a3..08c9301021 100644 --- a/LibGUI/GVariant.h +++ b/LibGUI/GVariant.h @@ -19,6 +19,12 @@ public: GVariant(Color); GVariant(const GVariant&); + GVariant& operator=(const GVariant&); + + GVariant(GVariant&&) = delete; + GVariant& operator=(GVariant&&) = delete; + + void clear(); ~GVariant(); enum class Type { @@ -84,7 +90,7 @@ public: String as_string() const { ASSERT(type() == Type::String); - return *m_value.as_string; + return m_value.as_string; } const GraphicsBitmap& as_bitmap() const @@ -118,6 +124,8 @@ public: bool operator<(const GVariant&) const; private: + void copy_from(const GVariant&); + struct RawPoint { int x; int y;