mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Make the state of StringBase private
Now it actually only exposes methods to allocate uninitialized storage and to create substring with a shared superstring. All the details of the memory layout are fully encapsulated.
This commit is contained in:
parent
fa52f68142
commit
611adf1591
Notes:
sideshowbarker
2024-07-17 08:36:27 +09:00
Author: https://github.com/DanShaders Commit: https://github.com/SerenityOS/serenity/commit/611adf1591 Pull-request: https://github.com/SerenityOS/serenity/pull/21661 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/kleinesfilmroellchen Reviewed-by: https://github.com/trflynn89
1 changed files with 15 additions and 15 deletions
|
@ -71,16 +71,6 @@ public:
|
||||||
void did_create_fly_string(Badge<FlyString>) const;
|
void did_create_fly_string(Badge<FlyString>) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// NOTE: If the least significant bit of the pointer is set, this is a short string.
|
|
||||||
static constexpr uintptr_t SHORT_STRING_FLAG = 1;
|
|
||||||
|
|
||||||
explicit StringBase(NonnullRefPtr<Detail::StringData const>);
|
|
||||||
|
|
||||||
explicit constexpr StringBase(ShortString short_string)
|
|
||||||
: m_short_string(short_string)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
ErrorOr<void> replace_with_new_string(size_t byte_count, Func&& callback)
|
ErrorOr<void> replace_with_new_string(size_t byte_count, Func&& callback)
|
||||||
{
|
{
|
||||||
|
@ -102,12 +92,17 @@ protected:
|
||||||
// is impossible to implement it without access to StringData.
|
// is impossible to implement it without access to StringData.
|
||||||
ErrorOr<StringBase> substring_from_byte_offset_with_shared_superstring(size_t start, size_t byte_count) const;
|
ErrorOr<StringBase> substring_from_byte_offset_with_shared_superstring(size_t start, size_t byte_count) const;
|
||||||
|
|
||||||
union {
|
|
||||||
ShortString m_short_string;
|
|
||||||
Detail::StringData const* m_data { nullptr };
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// NOTE: If the least significant bit of the pointer is set, this is a short string.
|
||||||
|
static constexpr uintptr_t SHORT_STRING_FLAG = 1;
|
||||||
|
|
||||||
|
explicit StringBase(NonnullRefPtr<Detail::StringData const>);
|
||||||
|
|
||||||
|
explicit constexpr StringBase(ShortString short_string)
|
||||||
|
: m_short_string(short_string)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<Bytes> replace_with_uninitialized_buffer(size_t byte_count);
|
ErrorOr<Bytes> replace_with_uninitialized_buffer(size_t byte_count);
|
||||||
|
|
||||||
constexpr Bytes replace_with_uninitialized_short_string(size_t byte_count)
|
constexpr Bytes replace_with_uninitialized_short_string(size_t byte_count)
|
||||||
|
@ -121,6 +116,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_string();
|
void destroy_string();
|
||||||
|
|
||||||
|
union {
|
||||||
|
ShortString m_short_string;
|
||||||
|
Detail::StringData const* m_data { nullptr };
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue