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:
Ali Mohammad Pur 2025-04-02 17:56:49 +02:00 committed by Andrew Kaster
commit eea81738cd
Notes: github-actions[bot] 2025-04-23 13:57:06 +00:00
11 changed files with 74 additions and 37 deletions

View file

@ -327,8 +327,8 @@ void URLSearchParams::sort()
// 1. Sort all name-value pairs, if any, by their names. Sorting must be done by comparison of code units. The relative order between name-value pairs with equal names must be preserved.
insertion_sort(m_list, [](auto& a, auto& b) {
// FIXME: There should be a way to do this without converting to utf16
auto a_utf16 = MUST(utf8_to_utf16(a.name));
auto b_utf16 = MUST(utf8_to_utf16(b.name));
auto a_utf16 = MUST(utf8_to_utf16(a.name)).data;
auto b_utf16 = MUST(utf8_to_utf16(b.name)).data;
auto common_length = min(a_utf16.size(), b_utf16.size());