1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

AK: Move String::~String() and String::destroy_string() to StringBase

This commit is contained in:
Dan Klishch 2023-10-28 15:42:33 -04:00 committed by Andrew Kaster
parent 54d149bc25
commit 1b09a1851e
4 changed files with 15 additions and 14 deletions

View file

@ -122,12 +122,6 @@ void StringData::compute_hash() const
} }
void String::destroy_string()
{
if (!is_short_string())
m_data->unref();
}
String String::from_utf8_without_validation(ReadonlyBytes bytes) String String::from_utf8_without_validation(ReadonlyBytes bytes)
{ {
if (bytes.size() <= MAX_SHORT_STRING_BYTE_COUNT) { if (bytes.size() <= MAX_SHORT_STRING_BYTE_COUNT) {

View file

@ -48,12 +48,6 @@ public:
using StringBase::StringBase; using StringBase::StringBase;
constexpr ~String()
{
if (!is_constant_evaluated())
destroy_string();
}
// Creates an empty (zero-length) String. // Creates an empty (zero-length) String.
constexpr String() constexpr String()
: StringBase(ShortString { SHORT_STRING_FLAG, {} }) : StringBase(ShortString { SHORT_STRING_FLAG, {} })
@ -209,8 +203,6 @@ public:
private: private:
using ShortString = Detail::ShortString; using ShortString = Detail::ShortString;
void destroy_string();
}; };
template<> template<>

View file

@ -73,4 +73,10 @@ bool StringBase::operator==(StringBase const& other) const
return bytes() == other.bytes(); return bytes() == other.bytes();
} }
void StringBase::destroy_string()
{
if (!is_short_string())
m_data->unref();
}
} }

View file

@ -42,6 +42,12 @@ public:
StringBase& operator=(StringBase&&); StringBase& operator=(StringBase&&);
StringBase& operator=(StringBase const&); StringBase& operator=(StringBase const&);
constexpr ~StringBase()
{
if (!is_constant_evaluated())
destroy_string();
}
// NOTE: This is primarily interesting to unit tests. // NOTE: This is primarily interesting to unit tests.
[[nodiscard]] bool is_short_string() const; [[nodiscard]] bool is_short_string() const;
@ -71,6 +77,9 @@ protected:
ShortString m_short_string; ShortString m_short_string;
Detail::StringData const* m_data { nullptr }; Detail::StringData const* m_data { nullptr };
}; };
private:
void destroy_string();
}; };
} }