1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:34:57 +00:00

AK: Store data in FlyString as StringBase

Unfortunately, it is not clear to me how to split this commit into
several atomic ones.
This commit is contained in:
Dan Klishch 2023-10-28 18:58:29 -04:00 committed by Andrew Kaster
parent e7700e16ee
commit fa52f68142
7 changed files with 42 additions and 145 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Badge.h>
#include <AK/StringBase.h>
#include <AK/StringInternals.h>
@ -81,9 +82,19 @@ bool StringBase::operator==(StringBase const& other) const
{
if (is_short_string())
return m_data == other.m_data;
if (other.is_short_string())
return false;
if (m_data->is_fly_string() && other.m_data->is_fly_string())
return m_data == other.m_data;
return bytes() == other.bytes();
}
void StringBase::did_create_fly_string(Badge<FlyString>) const
{
VERIFY(!is_short_string());
m_data->set_fly_string(true);
}
ErrorOr<Bytes> StringBase::replace_with_uninitialized_buffer(size_t byte_count)
{
if (byte_count <= MAX_SHORT_STRING_BYTE_COUNT)