mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
AK: Inline most StringBase member functions
More work on recovering the performance regression from DeprecatedFlyString removal. Local measurements on my MBP: - 2.5% speedup on Octane/zlib.js - 2% speedup on Octane/typescript.js
This commit is contained in:
parent
a0f3099333
commit
53cac71cec
Notes:
github-actions[bot]
2025-03-26 12:05:12 +00:00
Author: https://github.com/awesomekling
Commit: 53cac71cec
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4093
5 changed files with 109 additions and 104 deletions
|
@ -11,89 +11,6 @@
|
|||
|
||||
namespace AK::Detail {
|
||||
|
||||
ReadonlyBytes ShortString::bytes() const
|
||||
{
|
||||
return { storage, byte_count() };
|
||||
}
|
||||
|
||||
size_t ShortString::byte_count() const
|
||||
{
|
||||
return byte_count_and_short_string_flag >> StringBase::SHORT_STRING_BYTE_COUNT_SHIFT_COUNT;
|
||||
}
|
||||
|
||||
StringBase::StringBase(NonnullRefPtr<Detail::StringData const> data)
|
||||
: m_data(&data.leak_ref())
|
||||
{
|
||||
}
|
||||
|
||||
StringBase::StringBase(StringBase const& other)
|
||||
: m_data(other.m_data)
|
||||
{
|
||||
if (!is_short_string())
|
||||
m_data->ref();
|
||||
}
|
||||
|
||||
StringBase& StringBase::operator=(StringBase&& other)
|
||||
{
|
||||
if (!is_short_string())
|
||||
m_data->unref();
|
||||
|
||||
m_data = exchange(other.m_data, nullptr);
|
||||
other.m_short_string.byte_count_and_short_string_flag = SHORT_STRING_FLAG;
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringBase& StringBase::operator=(StringBase const& other)
|
||||
{
|
||||
if (&other != this) {
|
||||
if (!is_short_string())
|
||||
m_data->unref();
|
||||
|
||||
m_data = other.m_data;
|
||||
if (!is_short_string())
|
||||
m_data->ref();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ReadonlyBytes StringBase::bytes() const
|
||||
{
|
||||
ASSERT(!is_invalid());
|
||||
if (is_short_string())
|
||||
return m_short_string.bytes();
|
||||
return m_data->bytes();
|
||||
}
|
||||
|
||||
u32 StringBase::hash() const
|
||||
{
|
||||
ASSERT(!is_invalid());
|
||||
if (is_short_string()) {
|
||||
auto bytes = this->bytes();
|
||||
return string_hash(reinterpret_cast<char const*>(bytes.data()), bytes.size());
|
||||
}
|
||||
return m_data->hash();
|
||||
}
|
||||
|
||||
size_t StringBase::byte_count() const
|
||||
{
|
||||
ASSERT(!is_invalid());
|
||||
if (is_short_string())
|
||||
return m_short_string.byte_count_and_short_string_flag >> StringBase::SHORT_STRING_BYTE_COUNT_SHIFT_COUNT;
|
||||
return m_data->byte_count();
|
||||
}
|
||||
|
||||
bool StringBase::operator==(StringBase const& other) const
|
||||
{
|
||||
ASSERT(!is_invalid());
|
||||
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::replace_with_string_builder(StringBuilder& builder)
|
||||
{
|
||||
ASSERT(!is_invalid());
|
||||
|
@ -135,10 +52,4 @@ ErrorOr<StringBase> StringBase::substring_from_byte_offset_with_shared_superstri
|
|||
return StringBase { TRY(Detail::StringData::create_substring(*m_data, start, length)) };
|
||||
}
|
||||
|
||||
void StringBase::destroy_string()
|
||||
{
|
||||
if (!is_short_string())
|
||||
m_data->unref();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue