mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 08:08:43 +00:00
AK: Add template specializations for Optional<{,Fly}String>
Slice the size of `Optional<{,Fly}String>` in half by introducing `UINTPTR_MAX` as an invalid bit pattern for these values.
This commit is contained in:
parent
fcdf3014f1
commit
2457118024
Notes:
github-actions[bot]
2024-10-31 22:27:23 +00:00
Author: https://github.com/yyny
Commit: 2457118024
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2032
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/awesomekling
8 changed files with 427 additions and 2 deletions
|
@ -75,6 +75,8 @@ public:
|
|||
[[nodiscard]] ALWAYS_INLINE FlatPtr raw(Badge<FlyString>) const { return bit_cast<FlatPtr>(m_data); }
|
||||
|
||||
protected:
|
||||
bool is_invalid() const { return m_invalid_tag == UINTPTR_MAX; }
|
||||
|
||||
template<typename Func>
|
||||
ErrorOr<void> replace_with_new_string(size_t byte_count, Func&& callback)
|
||||
{
|
||||
|
@ -107,6 +109,11 @@ private:
|
|||
|
||||
explicit StringBase(NonnullRefPtr<Detail::StringData const>);
|
||||
|
||||
explicit constexpr StringBase(nullptr_t)
|
||||
: m_invalid_tag(UINTPTR_MAX)
|
||||
{
|
||||
}
|
||||
|
||||
explicit constexpr StringBase(ShortString short_string)
|
||||
: m_short_string(short_string)
|
||||
{
|
||||
|
@ -129,6 +136,7 @@ private:
|
|||
union {
|
||||
ShortString m_short_string;
|
||||
Detail::StringData const* m_data { nullptr };
|
||||
uintptr_t m_invalid_tag;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue