From 54a783db1746efe4e5c8775cc7cfb69e765c2fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 14 Jun 2023 21:08:21 +0000 Subject: [PATCH] style: Add a way to optimize the "attribute in no namespace exists" check Go through the slow path by default. No behavior change. Differential Revision: https://phabricator.services.mozilla.com/D180528 --- components/selectors/matching.rs | 6 +----- components/selectors/tree.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/selectors/matching.rs b/components/selectors/matching.rs index f347dc4078e..6a603f10abd 100644 --- a/components/selectors/matching.rs +++ b/components/selectors/matching.rs @@ -730,11 +730,7 @@ where Component::AttributeInNoNamespaceExists { ref local_name, ref local_name_lower, - } => element.attr_matches( - &NamespaceConstraint::Specific(&crate::parser::namespace_empty_string::()), - select_name(element, local_name, local_name_lower), - &AttrSelectorOperation::Exists, - ), + } => element.has_attr_in_no_namespace(select_name(element, local_name, local_name_lower)), Component::AttributeInNoNamespace { ref local_name, ref value, diff --git a/components/selectors/tree.rs b/components/selectors/tree.rs index fa150def0d6..560b1e61d81 100644 --- a/components/selectors/tree.rs +++ b/components/selectors/tree.rs @@ -80,6 +80,17 @@ pub trait Element: Sized + Clone + Debug { operation: &AttrSelectorOperation<&::AttrValue>, ) -> bool; + fn has_attr_in_no_namespace( + &self, + local_name: &::LocalName, + ) -> bool { + self.attr_matches( + &NamespaceConstraint::Specific(&crate::parser::namespace_empty_string::()), + local_name, + &AttrSelectorOperation::Exists, + ) + } + fn match_non_ts_pseudo_class( &self, pc: &::NonTSPseudoClass,