mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +01:00
style: Simplify selector flags setup even more
In my investigation for bug 1766439, I am digging into why selector matching regressed. It doesn't help that the selector-matching code is instantiated a gazillion times (so there's a ton of copies of the relevant functions). This was needed in the past because we had different ways of setting the selector flags on elements, but I unified that recently and now we only need to either set them or not. That is the kind of thing that MatchingContext is really good for, so pass that instead on MatchingContext creation. Differential Revision: https://phabricator.services.mozilla.com/D145428
This commit is contained in:
parent
db53845694
commit
4878422c93
14 changed files with 176 additions and 211 deletions
|
@ -1393,11 +1393,6 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
self.is_root_of_native_anonymous_subtree()
|
||||
}
|
||||
|
||||
fn set_selector_flags(&self, flags: ElementSelectorFlags) {
|
||||
debug_assert!(!flags.is_empty());
|
||||
self.set_flags(selector_flags_to_node_flags(flags));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn may_have_animations(&self) -> bool {
|
||||
if let Some(pseudo) = self.implemented_pseudo_element() {
|
||||
|
@ -1827,6 +1822,11 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
None
|
||||
}
|
||||
|
||||
fn set_selector_flags(&self, flags: ElementSelectorFlags) {
|
||||
debug_assert!(!flags.is_empty());
|
||||
self.set_flags(selector_flags_to_node_flags(flags));
|
||||
}
|
||||
|
||||
fn attr_matches(
|
||||
&self,
|
||||
ns: &NamespaceConstraint<&Namespace>,
|
||||
|
@ -1939,15 +1939,11 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
self.local_name() == other.local_name() && self.namespace() == other.namespace()
|
||||
}
|
||||
|
||||
fn match_non_ts_pseudo_class<F>(
|
||||
fn match_non_ts_pseudo_class(
|
||||
&self,
|
||||
pseudo_class: &NonTSPseudoClass,
|
||||
context: &mut MatchingContext<Self::Impl>,
|
||||
flags_setter: &mut F,
|
||||
) -> bool
|
||||
where
|
||||
F: FnMut(&Self, ElementSelectorFlags),
|
||||
{
|
||||
) -> bool {
|
||||
use selectors::matching::*;
|
||||
match *pseudo_class {
|
||||
NonTSPseudoClass::Autofill |
|
||||
|
@ -2003,7 +1999,9 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
self.is_link() && context.visited_handling().matches_visited()
|
||||
},
|
||||
NonTSPseudoClass::MozFirstNode => {
|
||||
flags_setter(self, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
|
||||
if context.needs_selector_flags() {
|
||||
self.apply_selector_flags(ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
|
||||
}
|
||||
let mut elem = self.as_node();
|
||||
while let Some(prev) = elem.prev_sibling() {
|
||||
if prev.contains_non_whitespace_content() {
|
||||
|
@ -2014,7 +2012,9 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
true
|
||||
},
|
||||
NonTSPseudoClass::MozLastNode => {
|
||||
flags_setter(self, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
|
||||
if context.needs_selector_flags() {
|
||||
self.apply_selector_flags(ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR);
|
||||
}
|
||||
let mut elem = self.as_node();
|
||||
while let Some(next) = elem.next_sibling() {
|
||||
if next.contains_non_whitespace_content() {
|
||||
|
@ -2025,7 +2025,9 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
true
|
||||
},
|
||||
NonTSPseudoClass::MozOnlyWhitespace => {
|
||||
flags_setter(self, ElementSelectorFlags::HAS_EMPTY_SELECTOR);
|
||||
if context.needs_selector_flags() {
|
||||
self.apply_selector_flags(ElementSelectorFlags::HAS_EMPTY_SELECTOR);
|
||||
}
|
||||
if self
|
||||
.as_node()
|
||||
.dom_children()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue