mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:47:45 +00:00
LibJS: Support move semantics for StringOrSymbol
This allows us to rehash property tables without a bunch of ref count churn happening.
This commit is contained in:
parent
1d96ecf148
commit
4387590e65
1 changed files with 12 additions and 0 deletions
|
@ -84,6 +84,11 @@ public:
|
||||||
as_string_impl().ref();
|
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_valid() const { return m_ptr != nullptr; }
|
||||||
ALWAYS_INLINE bool is_symbol() const { return is_valid() && (bits() & 1ul); }
|
ALWAYS_INLINE bool is_symbol() const { return is_valid() && (bits() & 1ul); }
|
||||||
ALWAYS_INLINE bool is_string() const { return is_valid() && !(bits() & 1ul); }
|
ALWAYS_INLINE bool is_string() const { return is_valid() && !(bits() & 1ul); }
|
||||||
|
@ -143,6 +148,13 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringOrSymbol& operator=(StringOrSymbol&& other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
m_ptr = exchange(other.m_ptr, nullptr);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned hash() const
|
unsigned hash() const
|
||||||
{
|
{
|
||||||
if (is_string())
|
if (is_string())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue