mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-15 23:09:05 +00:00
AK+Everywhere: Recognise that surrogates in utf16 aren't all that common
For the slight cost of counting code points when converting between encodings and a teeny bit of memory, this commit adds a fast path for all-happy utf-16 substrings and code point operations. This seems to be a significant chunk of time spent in many regex benchmarks.
This commit is contained in:
parent
86c756a589
commit
eea81738cd
Notes:
github-actions[bot]
2025-04-23 13:57:06 +00:00
Author: https://github.com/alimpfard
Commit: eea81738cd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4196
Reviewed-by: https://github.com/ADKaster ✅
11 changed files with 74 additions and 37 deletions
|
@ -113,16 +113,19 @@ public:
|
|||
RegexStringView construct_as_same(Span<u32> data, Optional<ByteString>& optional_string_storage, Utf16Data& optional_utf16_storage) const
|
||||
{
|
||||
auto view = m_view.visit(
|
||||
[&]<typename T>(T const&) {
|
||||
[&optional_string_storage, data]<typename T>(T const&) {
|
||||
StringBuilder builder;
|
||||
for (auto ch : data)
|
||||
builder.append(ch); // Note: The type conversion is intentional.
|
||||
optional_string_storage = builder.to_byte_string();
|
||||
return RegexStringView { T { *optional_string_storage } };
|
||||
},
|
||||
[&](Utf16View) {
|
||||
optional_utf16_storage = AK::utf32_to_utf16(Utf32View { data.data(), data.size() }).release_value_but_fixme_should_propagate_errors();
|
||||
return RegexStringView { Utf16View { optional_utf16_storage } };
|
||||
[&optional_utf16_storage, data](Utf16View) {
|
||||
auto conversion_result = utf32_to_utf16(Utf32View { data.data(), data.size() }).release_value_but_fixme_should_propagate_errors();
|
||||
optional_utf16_storage = conversion_result.data;
|
||||
auto view = Utf16View { optional_utf16_storage };
|
||||
view.unsafe_set_code_point_length(conversion_result.code_point_count);
|
||||
return RegexStringView { view };
|
||||
});
|
||||
|
||||
view.set_unicode(unicode());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue