AK: Implement a flyweight string for Utf16String

Utf16FlyString more or less works exactly the same as FlyString. It will
store the raw encoded data of the string instance. If the string is a
short ASCII string, Utf16FlyString holds the ShortString bytes; else,
Utf16FlyString holds a pointer to the Utf16StringData.
This commit is contained in:
Timothy Flynn 2025-06-20 11:52:35 -04:00 committed by Tim Flynn
commit 7f069efbc4
Notes: github-actions[bot] 2025-07-18 16:47:19 +00:00
9 changed files with 423 additions and 4 deletions

View file

@ -248,6 +248,21 @@ public:
return !has_short_ascii_storage();
}
[[nodiscard]] ALWAYS_INLINE Utf16StringData const* data(Badge<Utf16FlyString>) const
{
VERIFY(has_long_storage());
return data_without_union_member_assertion();
}
ALWAYS_INLINE void set_data(Badge<Utf16FlyString>, Utf16StringData const* data)
{
auto const** this_data = __builtin_launder(&m_value.data);
(*this_data) = data;
(*this_data)->ref();
}
[[nodiscard]] constexpr FlatPtr raw(Badge<Utf16FlyString>) const { return bit_cast<FlatPtr>(m_value); }
protected:
ALWAYS_INLINE void destroy_string() const
{