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
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

@ -1644,8 +1644,7 @@ Utf16String HTMLInputElement::value_sanitization_algorithm(Utf16String const& va
};
auto strip_newlines_and_trim = [&]() {
auto value_without_newlines = strip_newlines();
return Utf16String::from_utf16_without_validation(value_without_newlines.utf16_view().trim(Infra::ASCII_WHITESPACE));
return strip_newlines().trim(Infra::ASCII_WHITESPACE);
};
// https://html.spec.whatwg.org/multipage/input.html#text-(type=text)-state-and-search-state-(type=search):value-sanitization-algorithm