mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibURL: Avoid expensive IDNA::to_ascii() for all-ASCII domain strings
20% of CPU usage when loading https://utah.edu/ was spent doing these ASCII conversions in URL parsing.
This commit is contained in:
parent
520f6ac92a
commit
d568b15acf
Notes:
sideshowbarker
2024-07-17 06:40:21 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d568b15acf Pull-request: https://github.com/SerenityOS/serenity/pull/23859 Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 9 additions and 0 deletions
|
@ -580,6 +580,15 @@ static ErrorOr<String> domain_to_ascii(StringView domain, bool be_strict)
|
|||
{
|
||||
// 1. Let result be the result of running Unicode ToASCII with domain_name set to domain, UseSTD3ASCIIRules set to beStrict, CheckHyphens set to false, CheckBidi set to true, CheckJoiners set to true, Transitional_Processing set to false, and VerifyDnsLength set to beStrict. [UTS46]
|
||||
// 2. If result is a failure value, domain-to-ASCII validation error, return failure.
|
||||
|
||||
// OPTIMIZATION: Fast path for all-ASCII domain strings.
|
||||
if (all_of(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");
|
||||
return String::from_utf8_without_validation(domain.bytes());
|
||||
}
|
||||
|
||||
Unicode::IDNA::ToAsciiOptions const options {
|
||||
Unicode::IDNA::CheckHyphens::No,
|
||||
Unicode::IDNA::CheckBidi::Yes,
|
||||
|
|
Loading…
Reference in a new issue