mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
AK: Specialize Optional for Utf16String and Utf16FlyString
We added this for String some time ago, so let's give Utf16String the
same optimization. Note that Utf16String was already handling its data
member potentially being null as of 5af99f4dd0.
This commit is contained in:
parent
9e29d0c040
commit
1869399fd1
Notes:
github-actions[bot]
2025-08-19 10:25:10 +00:00
Author: https://github.com/trflynn89
Commit: 1869399fd1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5904
5 changed files with 251 additions and 1 deletions
|
|
@ -146,3 +146,27 @@ TEST_CASE(is_one_of)
|
|||
EXPECT(bar.is_one_of("bar"sv, "foo"sv));
|
||||
EXPECT(bar.is_one_of("bar"sv));
|
||||
}
|
||||
|
||||
TEST_CASE(optional)
|
||||
{
|
||||
static_assert(AssertSize<Optional<Utf16FlyString>, sizeof(Utf16FlyString)>());
|
||||
|
||||
Optional<Utf16FlyString> string;
|
||||
EXPECT(!string.has_value());
|
||||
|
||||
string = "ascii"_utf16_fly_string;
|
||||
EXPECT(string.has_value());
|
||||
EXPECT_EQ(string.value(), "ascii"sv);
|
||||
|
||||
auto released = string.release_value();
|
||||
EXPECT(!string.has_value());
|
||||
EXPECT_EQ(released, "ascii"sv);
|
||||
|
||||
string = u"well π hello"_utf16_fly_string;
|
||||
EXPECT(string.has_value());
|
||||
EXPECT_EQ(string.value(), u"well π hello"sv);
|
||||
|
||||
released = string.release_value();
|
||||
EXPECT(!string.has_value());
|
||||
EXPECT_EQ(released, u"well π hello"sv);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1271,3 +1271,27 @@ TEST_CASE(code_point_at)
|
|||
test(u"π"sv, 1);
|
||||
test(u"hello π there!"sv, 14);
|
||||
}
|
||||
|
||||
TEST_CASE(optional)
|
||||
{
|
||||
static_assert(AssertSize<Optional<Utf16String>, sizeof(Utf16String)>());
|
||||
|
||||
Optional<Utf16String> string;
|
||||
EXPECT(!string.has_value());
|
||||
|
||||
string = "ascii"_utf16;
|
||||
EXPECT(string.has_value());
|
||||
EXPECT_EQ(string.value(), "ascii"sv);
|
||||
|
||||
auto released = string.release_value();
|
||||
EXPECT(!string.has_value());
|
||||
EXPECT_EQ(released, "ascii"sv);
|
||||
|
||||
string = u"well π hello"_utf16;
|
||||
EXPECT(string.has_value());
|
||||
EXPECT_EQ(string.value(), u"well π hello"sv);
|
||||
|
||||
released = string.release_value();
|
||||
EXPECT(!string.has_value());
|
||||
EXPECT_EQ(released, u"well π hello"sv);
|
||||
}
|
||||
|
|
|
|||
Loadingβ¦
Add table
Add a link
Reference in a new issue