mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-17 13:17:33 +00:00
AK: Introduce StringBase::replace_with_new_{short_,}string
This commit is contained in:
committed by
Andrew Kaster
parent
d6290c4684
commit
dcd1fda9c8
@@ -54,11 +54,6 @@ StringBase& StringBase::operator=(StringBase const& other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
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())
|
||||
@@ -82,6 +77,17 @@ bool StringBase::operator==(StringBase const& other) const
|
||||
return bytes() == other.bytes();
|
||||
}
|
||||
|
||||
ErrorOr<Bytes> StringBase::replace_with_uninitialized_buffer(size_t byte_count)
|
||||
{
|
||||
if (byte_count <= MAX_SHORT_STRING_BYTE_COUNT)
|
||||
return replace_with_uninitialized_short_string(byte_count);
|
||||
|
||||
u8* buffer = nullptr;
|
||||
destroy_string();
|
||||
m_data = &TRY(StringData::create_uninitialized(byte_count, buffer)).leak_ref();
|
||||
return Bytes { buffer, byte_count };
|
||||
}
|
||||
|
||||
void StringBase::destroy_string()
|
||||
{
|
||||
if (!is_short_string())
|
||||
|
||||
Reference in New Issue
Block a user