mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
LibJS: Make StringOrSymbol not leak strings
Ideally this thing would not allocate strings at all, but I'll leave that as a separate exercise.
This commit is contained in:
parent
bc27aa9b6f
commit
6444f49d22
1 changed files with 10 additions and 0 deletions
|
@ -55,6 +55,12 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~StringOrSymbol()
|
||||||
|
{
|
||||||
|
if (is_string())
|
||||||
|
reinterpret_cast<const StringImpl*>(m_ptr)->unref();
|
||||||
|
}
|
||||||
|
|
||||||
StringOrSymbol(const Symbol* symbol)
|
StringOrSymbol(const Symbol* symbol)
|
||||||
: m_ptr(symbol)
|
: m_ptr(symbol)
|
||||||
{
|
{
|
||||||
|
@ -64,6 +70,8 @@ public:
|
||||||
StringOrSymbol(const StringOrSymbol& other)
|
StringOrSymbol(const StringOrSymbol& other)
|
||||||
{
|
{
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
|
if (is_string())
|
||||||
|
reinterpret_cast<const StringImpl*>(m_ptr)->ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE bool is_valid() const { return m_ptr != nullptr; }
|
ALWAYS_INLINE bool is_valid() const { return m_ptr != nullptr; }
|
||||||
|
@ -120,6 +128,8 @@ public:
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
|
if (is_string())
|
||||||
|
reinterpret_cast<const StringImpl*>(m_ptr)->ref();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue