From 4387590e65e05019d92d9b7244681f38bf609f77 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 15 Oct 2020 23:32:54 +0200 Subject: [PATCH] LibJS: Support move semantics for StringOrSymbol This allows us to rehash property tables without a bunch of ref count churn happening. --- Libraries/LibJS/Runtime/StringOrSymbol.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Libraries/LibJS/Runtime/StringOrSymbol.h b/Libraries/LibJS/Runtime/StringOrSymbol.h index b2f42641a8..3273e7f640 100644 --- a/Libraries/LibJS/Runtime/StringOrSymbol.h +++ b/Libraries/LibJS/Runtime/StringOrSymbol.h @@ -84,6 +84,11 @@ public: as_string_impl().ref(); } + StringOrSymbol(StringOrSymbol&& other) + { + m_ptr = exchange(other.m_ptr, nullptr); + } + ALWAYS_INLINE bool is_valid() const { return m_ptr != nullptr; } ALWAYS_INLINE bool is_symbol() const { return is_valid() && (bits() & 1ul); } ALWAYS_INLINE bool is_string() const { return is_valid() && !(bits() & 1ul); } @@ -143,6 +148,13 @@ public: return *this; } + StringOrSymbol& operator=(StringOrSymbol&& other) + { + if (this != &other) + m_ptr = exchange(other.m_ptr, nullptr); + return *this; + } + unsigned hash() const { if (is_string())