mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
selectors: Simplify :visited by only using the "is inside link" information.
Right now we go through a lot of hoops to see if we ever see a relevant link. However, that information is not needed: if the element is a link, we'll always need to compute its visited style because its its own relevant link. If the element inherits from a link, we need to also compute the visited style anyway. So the "has a relevant link been found" is pretty useless when we know what are we inheriting from. The branches at the beginning of matches_complex_selector_internal were affecting performance, and there are no good reasons to keep them. I've verified that this passes all the visited tests in mozilla central, and that the test-cases too-flaky to be landed still pass.
This commit is contained in:
parent
e4bb3a102e
commit
3119db724a
10 changed files with 128 additions and 208 deletions
|
@ -48,6 +48,26 @@ pub enum VisitedHandlingMode {
|
|||
RelevantLinkVisited,
|
||||
}
|
||||
|
||||
impl VisitedHandlingMode {
|
||||
#[inline]
|
||||
pub fn matches_visited(&self) -> bool {
|
||||
matches!(
|
||||
*self,
|
||||
VisitedHandlingMode::RelevantLinkVisited |
|
||||
VisitedHandlingMode::AllLinksVisitedAndUnvisited
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn matches_unvisited(&self) -> bool {
|
||||
matches!(
|
||||
*self,
|
||||
VisitedHandlingMode::AllLinksUnvisited |
|
||||
VisitedHandlingMode::AllLinksVisitedAndUnvisited
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Which quirks mode is this document in.
|
||||
///
|
||||
/// See: https://quirks.spec.whatwg.org/
|
||||
|
@ -87,12 +107,6 @@ where
|
|||
pub nth_index_cache: Option<&'a mut NthIndexCache>,
|
||||
/// Input that controls how matching for links is handled.
|
||||
pub visited_handling: VisitedHandlingMode,
|
||||
/// Output that records whether we encountered a "relevant link" while
|
||||
/// matching _any_ selector for this element. (This differs from
|
||||
/// `RelevantLinkStatus` which tracks the status for the _current_ selector
|
||||
/// only.)
|
||||
pub relevant_link_found: bool,
|
||||
|
||||
/// The element which is going to match :scope pseudo-class. It can be
|
||||
/// either one :scope element, or the scoping element.
|
||||
///
|
||||
|
@ -107,6 +121,9 @@ where
|
|||
pub scope_element: Option<OpaqueElement>,
|
||||
|
||||
/// The current nesting level of selectors that we're matching.
|
||||
///
|
||||
/// FIXME(emilio): Move this somewhere else and make MatchingContext
|
||||
/// immutable again.
|
||||
pub nesting_level: usize,
|
||||
|
||||
/// An optional hook function for checking whether a pseudo-element
|
||||
|
@ -152,7 +169,6 @@ where
|
|||
visited_handling,
|
||||
nth_index_cache,
|
||||
quirks_mode,
|
||||
relevant_link_found: false,
|
||||
classes_and_ids_case_sensitivity: quirks_mode.classes_and_ids_case_sensitivity(),
|
||||
scope_element: None,
|
||||
nesting_level: 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue