mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 15:39:55 +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
Notes:
sideshowbarker
2024-07-19 03:32:21 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6444f49d22d
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)
|
||||
: m_ptr(symbol)
|
||||
{
|
||||
|
@ -64,6 +70,8 @@ public:
|
|||
StringOrSymbol(const StringOrSymbol& other)
|
||||
{
|
||||
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; }
|
||||
|
@ -120,6 +128,8 @@ public:
|
|||
if (this == &other)
|
||||
return *this;
|
||||
m_ptr = other.m_ptr;
|
||||
if (is_string())
|
||||
reinterpret_cast<const StringImpl*>(m_ptr)->ref();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue