aboutsummaryrefslogtreecommitdiffstats
path: root/components/selectors/context.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2017-12-08 04:48:03 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2017-12-08 05:35:12 +0100
commit3119db724aa1ba257b919799e3783e2a047bf28f (patch)
treed0f96edc14c67b5e577e0ae37398c3f06910f79e /components/selectors/context.rs
parente4bb3a102e4965e7867de03d39aee83d36598e4f (diff)
downloadservo-3119db724aa1ba257b919799e3783e2a047bf28f.tar.gz
servo-3119db724aa1ba257b919799e3783e2a047bf28f.zip
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.
Diffstat (limited to 'components/selectors/context.rs')
-rw-r--r--components/selectors/context.rs30
1 files changed, 23 insertions, 7 deletions
diff --git a/components/selectors/context.rs b/components/selectors/context.rs
index b129e8e1558..ca7a2bfcb60 100644
--- a/components/selectors/context.rs
+++ b/components/selectors/context.rs
@@ -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,