mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
LibWeb: Prefer using equals_ignoring_ascii_case
Which has an optmization if both size of the string being passed through are FlyStrings, which actually ends up being the case in some places during selector matching comparing attribute names. Instead of maintaining more overloads of Infra::is_ascii_case_insensitive_match, switch everything over to equals_ignoring_ascii_case instead.
This commit is contained in:
parent
cfc241f61d
commit
579730d861
Notes:
github-actions[bot]
2025-05-21 12:46:04 +00:00
Author: https://github.com/shannonbooth
Commit: 579730d861
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4799
Reviewed-by: https://github.com/AtkinsSJ ✅
24 changed files with 78 additions and 87 deletions
|
@ -176,7 +176,7 @@ WebIDL::ExceptionOr<Optional<Vector<XHR::FormDataEntry>>> construct_entry_list(J
|
|||
}
|
||||
}
|
||||
// 9. Otherwise, if the field element is an input element whose type attribute is in the Hidden state and name is an ASCII case-insensitive match for "_charset_":
|
||||
else if (auto* hidden_input = dynamic_cast<HTML::HTMLInputElement*>(control.ptr()); hidden_input && hidden_input->type_state() == HTMLInputElement::TypeAttributeState::Hidden && Infra::is_ascii_case_insensitive_match(name, "_charset_"sv)) {
|
||||
else if (auto* hidden_input = dynamic_cast<HTML::HTMLInputElement*>(control.ptr()); hidden_input && hidden_input->type_state() == HTMLInputElement::TypeAttributeState::Hidden && name.equals_ignoring_ascii_case("_charset_"sv)) {
|
||||
// 1. Let charset be the name of encoding if encoding is given, and "UTF-8" otherwise.
|
||||
auto charset = encoding.has_value() ? encoding.value() : "UTF-8"_string;
|
||||
|
||||
|
|
|
@ -999,7 +999,7 @@ TokenizedFeature::NoOpener HTMLElement::get_an_elements_noopener(URL::URL const&
|
|||
|
||||
// 2. If element's link types do not include the opener keyword and
|
||||
// target is an ASCII case-insensitive match for "_blank", then return true.
|
||||
if (!link_types.contains_slow("opener"sv) && Infra::is_ascii_case_insensitive_match(target, "_blank"sv))
|
||||
if (!link_types.contains_slow("opener"sv) && target.equals_ignoring_ascii_case("_blank"sv))
|
||||
return TokenizedFeature::NoOpener::Yes;
|
||||
|
||||
// 3. If url's blob URL entry is not null:
|
||||
|
|
|
@ -432,8 +432,8 @@ String HTMLFormElement::action_from_form_element(GC::Ref<HTMLElement> element) c
|
|||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-attributes:attr-fs-method-2
|
||||
static HTMLFormElement::MethodAttributeState method_attribute_to_method_state(StringView method)
|
||||
{
|
||||
#define __ENUMERATE_FORM_METHOD_ATTRIBUTE(keyword, state) \
|
||||
if (Infra::is_ascii_case_insensitive_match(#keyword##sv, method)) \
|
||||
#define __ENUMERATE_FORM_METHOD_ATTRIBUTE(keyword, state) \
|
||||
if (#keyword##sv.equals_ignoring_ascii_case(method)) \
|
||||
return HTMLFormElement::MethodAttributeState::state;
|
||||
ENUMERATE_FORM_METHOD_ATTRIBUTES
|
||||
#undef __ENUMERATE_FORM_METHOD_ATTRIBUTE
|
||||
|
@ -467,8 +467,8 @@ HTMLFormElement::MethodAttributeState HTMLFormElement::method_state_from_form_el
|
|||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-attributes:attr-fs-enctype-2
|
||||
static HTMLFormElement::EncodingTypeAttributeState encoding_type_attribute_to_encoding_type_state(StringView encoding_type)
|
||||
{
|
||||
#define __ENUMERATE_FORM_METHOD_ENCODING_TYPE(keyword, state) \
|
||||
if (Infra::is_ascii_case_insensitive_match(keyword##sv, encoding_type)) \
|
||||
#define __ENUMERATE_FORM_METHOD_ENCODING_TYPE(keyword, state) \
|
||||
if (keyword##sv.equals_ignoring_ascii_case(encoding_type)) \
|
||||
return HTMLFormElement::EncodingTypeAttributeState::state;
|
||||
ENUMERATE_FORM_METHOD_ENCODING_TYPES
|
||||
#undef __ENUMERATE_FORM_METHOD_ENCODING_TYPE
|
||||
|
|
|
@ -2559,7 +2559,7 @@ Optional<double> HTMLInputElement::allowed_value_step() const
|
|||
auto step_string = *maybe_step_string;
|
||||
|
||||
// 3. Otherwise, if the attribute's value is an ASCII case-insensitive match for the string "any", then there is no allowed value step.
|
||||
if (Infra::is_ascii_case_insensitive_match(step_string, "any"_string))
|
||||
if (step_string.equals_ignoring_ascii_case("any"sv))
|
||||
return {};
|
||||
|
||||
// 4. Otherwise, if the rules for parsing floating-point number values, when they are applied to the attribute's value, return an error,
|
||||
|
|
|
@ -229,12 +229,12 @@ void HTMLScriptElement::prepare_script()
|
|||
m_script_type = ScriptType::Classic;
|
||||
}
|
||||
// 10. Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "module",
|
||||
else if (Infra::is_ascii_case_insensitive_match(script_block_type, "module"sv)) {
|
||||
else if (script_block_type.equals_ignoring_ascii_case("module"sv)) {
|
||||
// then set el's type to "module".
|
||||
m_script_type = ScriptType::Module;
|
||||
}
|
||||
// 11. Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "importmap",
|
||||
else if (Infra::is_ascii_case_insensitive_match(script_block_type, "importmap"sv)) {
|
||||
else if (script_block_type.equals_ignoring_ascii_case("importmap"sv)) {
|
||||
// then set el's type to "importmap".
|
||||
m_script_type = ScriptType::ImportMap;
|
||||
}
|
||||
|
@ -290,14 +290,14 @@ void HTMLScriptElement::prepare_script()
|
|||
event = MUST(event.trim(Infra::ASCII_WHITESPACE));
|
||||
|
||||
// 4. If for is not an ASCII case-insensitive match for the string "window", then return.
|
||||
if (!Infra::is_ascii_case_insensitive_match(for_, "window"sv)) {
|
||||
if (!for_.equals_ignoring_ascii_case("window"sv)) {
|
||||
dbgln("HTMLScriptElement: Refusing to run classic script because the provided 'for' attribute is not equal to 'window'");
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. If event is not an ASCII case-insensitive match for either the string "onload" or the string "onload()", then return.
|
||||
if (!Infra::is_ascii_case_insensitive_match(event, "onload"sv)
|
||||
&& !Infra::is_ascii_case_insensitive_match(event, "onload()"sv)) {
|
||||
if (!event.equals_ignoring_ascii_case("onload"sv)
|
||||
&& !event.equals_ignoring_ascii_case("onload()"sv)) {
|
||||
dbgln("HTMLScriptElement: Refusing to run classic script because the provided 'event' attribute is not equal to 'onload' or 'onload()'");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -372,13 +372,13 @@ Navigable::ChosenNavigable Navigable::choose_a_navigable(StringView name, Tokeni
|
|||
auto sandboxing_flag_set = active_document()->active_sandboxing_flag_set();
|
||||
|
||||
// 4. If name is the empty string or an ASCII case-insensitive match for "_self", then set chosen to currentNavigable.
|
||||
if (name.is_empty() || Infra::is_ascii_case_insensitive_match(name, "_self"sv)) {
|
||||
if (name.is_empty() || name.equals_ignoring_ascii_case("_self"sv)) {
|
||||
chosen = this;
|
||||
}
|
||||
|
||||
// 5. Otherwise, if name is an ASCII case-insensitive match for "_parent",
|
||||
// set chosen to currentNavigable's parent, if any, and currentNavigable otherwise.
|
||||
else if (Infra::is_ascii_case_insensitive_match(name, "_parent"sv)) {
|
||||
else if (name.equals_ignoring_ascii_case("_parent"sv)) {
|
||||
if (auto parent = this->parent())
|
||||
chosen = parent;
|
||||
else
|
||||
|
@ -387,13 +387,13 @@ Navigable::ChosenNavigable Navigable::choose_a_navigable(StringView name, Tokeni
|
|||
|
||||
// 6. Otherwise, if name is an ASCII case-insensitive match for "_top",
|
||||
// set chosen to currentNavigable's traversable navigable.
|
||||
else if (Infra::is_ascii_case_insensitive_match(name, "_top"sv)) {
|
||||
else if (name.equals_ignoring_ascii_case("_top"sv)) {
|
||||
chosen = traversable_navigable();
|
||||
}
|
||||
|
||||
// 7. Otherwise, if name is not an ASCII case-insensitive match for "_blank" and noopener is false, then set chosen
|
||||
// to the result of finding a navigable by target name given name and currentNavigable.
|
||||
else if (!Infra::is_ascii_case_insensitive_match(name, "_blank"sv) && no_opener == TokenizedFeature::NoOpener::No) {
|
||||
else if (!name.equals_ignoring_ascii_case("_blank"sv) && no_opener == TokenizedFeature::NoOpener::No) {
|
||||
chosen = find_a_navigable_by_target_name(name);
|
||||
}
|
||||
|
||||
|
@ -446,7 +446,7 @@ Navigable::ChosenNavigable Navigable::choose_a_navigable(StringView name, Tokeni
|
|||
String target_name;
|
||||
|
||||
// 6. If name is not an ASCII case-insensitive match for "_blank", then set targetName to name.
|
||||
if (!Infra::is_ascii_case_insensitive_match(name, "_blank"sv))
|
||||
if (!name.equals_ignoring_ascii_case("_blank"sv))
|
||||
target_name = MUST(String::from_utf8(name));
|
||||
|
||||
auto create_new_traversable_closure = [this, no_opener, target_name, activate_tab, window_features](GC::Ptr<BrowsingContext> opener) -> GC::Ref<Navigable> {
|
||||
|
|
|
@ -5071,7 +5071,7 @@ Optional<Color> parse_legacy_color_value(StringView string_view)
|
|||
input = input.trim(Infra::ASCII_WHITESPACE);
|
||||
|
||||
// 3. If input is an ASCII case-insensitive match for "transparent", then return failure.
|
||||
if (Infra::is_ascii_case_insensitive_match(input, "transparent"sv))
|
||||
if (input.equals_ignoring_ascii_case("transparent"sv))
|
||||
return {};
|
||||
|
||||
// 4. If input is an ASCII case-insensitive match for one of the named colors, then return the CSS color corresponding to that keyword. [CSSCOLOR]
|
||||
|
|
|
@ -892,7 +892,7 @@ static WebIDL::ExceptionOr<String> serialize_processing_instruction(DOM::Process
|
|||
if (processing_instruction.target().contains(':'))
|
||||
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target contains a colon"_string);
|
||||
|
||||
if (Infra::is_ascii_case_insensitive_match(processing_instruction.target(), "xml"sv))
|
||||
if (processing_instruction.target().equals_ignoring_ascii_case("xml"sv))
|
||||
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target is equal to 'xml'"_string);
|
||||
|
||||
// 2. If the require well-formed flag is set (its value is true), and node's data contains characters that are not matched by the XML Char production or contains
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue