AK+LibURL+LibWeb: Use simdutf to validate ASCII strings

simdutf provides a vectorized ASCII validator, so let's use that instead
of looping over strings manually.
This commit is contained in:
Timothy Flynn 2025-04-06 08:39:05 -04:00 committed by Tim Flynn
commit ee6b2db009
Notes: github-actions[bot] 2025-04-06 15:06:55 +00:00
10 changed files with 32 additions and 11 deletions

View file

@ -196,7 +196,7 @@ Optional<String> Host::public_suffix() const
auto public_suffix = get_public_suffix(host_string.bytes_as_string_view()).value_or("*"_string);
// 4. Assert: publicSuffix is an ASCII string that does not end with ".".
VERIFY(all_of(public_suffix.code_points(), is_ascii));
VERIFY(public_suffix.is_ascii());
VERIFY(!public_suffix.ends_with('.'));
// 5. Return publicSuffix and trailingDot concatenated.
@ -223,7 +223,7 @@ Optional<String> Host::registrable_domain() const
auto registrable_domain = get_registrable_domain(host_string).value_or("*"_string);
// 4. Assert: registrableDomain is an ASCII string that does not end with ".".
VERIFY(all_of(registrable_domain.code_points(), is_ascii));
VERIFY(registrable_domain.is_ascii());
VERIFY(!registrable_domain.ends_with('.'));
// 5. Return registrableDomain and trailingDot concatenated.

View file

@ -514,7 +514,7 @@ static ErrorOr<String> domain_to_ascii(StringView domain, bool be_strict)
// OPTIMIZATION: If beStrict is false, domain is an ASCII string, and strictly splitting domain on U+002E (.)
// does not produce any item that starts with an ASCII case-insensitive match for "xn--", this
// step is equivalent to ASCII lowercasing domain.
if (!be_strict && all_of(domain, is_ascii)) {
if (!be_strict && domain.is_ascii()) {
// 3. If result is the empty string, domain-to-ASCII validation error, return failure.
if (domain.is_empty())
return Error::from_string_literal("Empty domain");

View file

@ -14,7 +14,7 @@ namespace URL::Pattern {
String escape_a_pattern_string(String const& input)
{
// 1. Assert: input is an ASCII string.
VERIFY(all_of(input.code_points(), is_ascii));
VERIFY(input.is_ascii());
// 2. Let result be the empty string.
StringBuilder result;
@ -51,7 +51,7 @@ String escape_a_pattern_string(String const& input)
String escape_a_regexp_string(String const& input)
{
// 1. Assert: input is an ASCII string.
VERIFY(all_of(input.code_points(), is_ascii));
VERIFY(input.is_ascii());
// 2. Let result be the empty string.
StringBuilder builder;