AK: Add trim methods to Utf16String that skip allocation when not needed

If the string does not begin with any of the provided code units, we do
not need to create a new string.
This commit is contained in:
Timothy Flynn 2025-08-05 07:08:05 -04:00 committed by Jelle Raaijmakers
parent 0efa98a57a
commit 2dc0a3b3ce
Notes: github-actions[bot] 2025-08-05 13:15:06 +00:00
5 changed files with 84 additions and 5 deletions

View file

@ -105,7 +105,7 @@ Utf16String strip_and_collapse_whitespace(Utf16String const& string)
}
// ...and then remove any leading and trailing ASCII whitespace from that string.
return Utf16String::from_utf16(builder.utf16_string_view().trim(Infra::ASCII_WHITESPACE));
return builder.to_utf16_string().trim(Infra::ASCII_WHITESPACE);
}
// https://infra.spec.whatwg.org/#code-unit-prefix