1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 07:54:58 +00:00

AK: Move String::bytes() and String::operator==(String) to StringBase

The idea is to eventually get rid of protected state in StringBase. To
do this, we first need to remove all references to m_data and
m_short_string from String.
This commit is contained in:
Dan Klishch 2023-10-28 15:37:10 -04:00 committed by Andrew Kaster
parent 4364a28d3d
commit 54d149bc25
4 changed files with 21 additions and 19 deletions

View file

@ -59,4 +59,18 @@ bool StringBase::is_short_string() const
return has_short_string_bit(reinterpret_cast<uintptr_t>(m_data));
}
ReadonlyBytes StringBase::bytes() const
{
if (is_short_string())
return m_short_string.bytes();
return m_data->bytes();
}
bool StringBase::operator==(StringBase const& other) const
{
if (is_short_string())
return m_data == other.m_data;
return bytes() == other.bytes();
}
}