mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
AK: Tweak ShortString bit layout slightly
Move the byte count one step to the left in order to make space for the JS::StringOrSymbol flag.
This commit is contained in:
parent
50e9ffbeec
commit
b11f3853a8
2 changed files with 5 additions and 3 deletions
|
@ -18,7 +18,7 @@ ReadonlyBytes ShortString::bytes() const
|
|||
|
||||
size_t ShortString::byte_count() const
|
||||
{
|
||||
return byte_count_and_short_string_flag >> 1;
|
||||
return byte_count_and_short_string_flag >> StringBase::SHORT_STRING_BYTE_COUNT_SHIFT_COUNT;
|
||||
}
|
||||
|
||||
StringBase::StringBase(NonnullRefPtr<Detail::StringData const> data)
|
||||
|
@ -78,7 +78,7 @@ size_t StringBase::byte_count() const
|
|||
{
|
||||
ASSERT(!is_invalid());
|
||||
if (is_short_string())
|
||||
return m_short_string.byte_count_and_short_string_flag >> 1;
|
||||
return m_short_string.byte_count_and_short_string_flag >> StringBase::SHORT_STRING_BYTE_COUNT_SHIFT_COUNT;
|
||||
return m_data->byte_count();
|
||||
}
|
||||
|
||||
|
|
|
@ -103,9 +103,11 @@ protected:
|
|||
private:
|
||||
friend class ::AK::String;
|
||||
friend class ::AK::FlyString;
|
||||
friend struct ::AK::Detail::ShortString;
|
||||
|
||||
// NOTE: If the least significant bit of the pointer is set, this is a short string.
|
||||
static constexpr uintptr_t SHORT_STRING_FLAG = 1;
|
||||
static constexpr unsigned SHORT_STRING_BYTE_COUNT_SHIFT_COUNT = 2;
|
||||
|
||||
explicit StringBase(NonnullRefPtr<Detail::StringData const>);
|
||||
|
||||
|
@ -127,7 +129,7 @@ private:
|
|||
VERIFY(byte_count <= MAX_SHORT_STRING_BYTE_COUNT);
|
||||
|
||||
m_short_string = ShortString {};
|
||||
m_short_string.byte_count_and_short_string_flag = (byte_count << 1) | SHORT_STRING_FLAG;
|
||||
m_short_string.byte_count_and_short_string_flag = (byte_count << SHORT_STRING_BYTE_COUNT_SHIFT_COUNT) | SHORT_STRING_FLAG;
|
||||
return { m_short_string.storage, byte_count };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue