diff --git a/AK/String.cpp b/AK/String.cpp index c61be2b95d..a0a9147235 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -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) { if (bytes.size() <= MAX_SHORT_STRING_BYTE_COUNT) { diff --git a/AK/String.h b/AK/String.h index 672597036e..0dbd6f46e8 100644 --- a/AK/String.h +++ b/AK/String.h @@ -48,12 +48,6 @@ public: using StringBase::StringBase; - constexpr ~String() - { - if (!is_constant_evaluated()) - destroy_string(); - } - // Creates an empty (zero-length) String. constexpr String() : StringBase(ShortString { SHORT_STRING_FLAG, {} }) @@ -209,8 +203,6 @@ public: private: using ShortString = Detail::ShortString; - - void destroy_string(); }; template<> diff --git a/AK/StringBase.cpp b/AK/StringBase.cpp index 944c8df6f2..2a289bd884 100644 --- a/AK/StringBase.cpp +++ b/AK/StringBase.cpp @@ -73,4 +73,10 @@ bool StringBase::operator==(StringBase const& other) const return bytes() == other.bytes(); } +void StringBase::destroy_string() +{ + if (!is_short_string()) + m_data->unref(); +} + } diff --git a/AK/StringBase.h b/AK/StringBase.h index 302a9b211e..60b80a112f 100644 --- a/AK/StringBase.h +++ b/AK/StringBase.h @@ -42,6 +42,12 @@ public: StringBase& operator=(StringBase&&); StringBase& operator=(StringBase const&); + constexpr ~StringBase() + { + if (!is_constant_evaluated()) + destroy_string(); + } + // NOTE: This is primarily interesting to unit tests. [[nodiscard]] bool is_short_string() const; @@ -71,6 +77,9 @@ protected: ShortString m_short_string; Detail::StringData const* m_data { nullptr }; }; + +private: + void destroy_string(); }; }