aboutsummaryrefslogtreecommitdiffstats
path: root/components/selectors/context.rs
diff options
context:
space:
mode:
authorZach Hoffman <zach@zrhoffman.net>2023-01-16 11:26:41 +0000
committerMartin Robinson <mrobinson@igalia.com>2023-11-04 08:17:09 +0100
commit3076481c52eff296bd784a010cfdf2683107681a (patch)
tree7e8ede9e3a12aad26103eb9fc54fc0911145b95e /components/selectors/context.rs
parenta973371cf27946fc18d31cd967c67b5308b91ac1 (diff)
downloadservo-3076481c52eff296bd784a010cfdf2683107681a.tar.gz
servo-3076481c52eff296bd784a010cfdf2683107681a.zip
style: Implement selector matching for :nth-child(An+B of selector list) and :nth-last-child(An+B of selector list)
Since we have been using a single hash map to cache all :nth-child indices (with no selector list), each different selector will need its own cache. As a side note, this patch does not address invalidation. Differential Revision: https://phabricator.services.mozilla.com/D166266
Diffstat (limited to 'components/selectors/context.rs')
-rw-r--r--components/selectors/context.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/components/selectors/context.rs b/components/selectors/context.rs
index e29abe639a1..ffb97c94e8b 100644
--- a/components/selectors/context.rs
+++ b/components/selectors/context.rs
@@ -4,8 +4,8 @@
use crate::attr::CaseSensitivity;
use crate::bloom::BloomFilter;
-use crate::nth_index_cache::NthIndexCache;
-use crate::parser::SelectorImpl;
+use crate::nth_index_cache::{NthIndexCache, NthIndexCacheInner};
+use crate::parser::{Selector, SelectorImpl};
use crate::tree::{Element, OpaqueElement};
/// What kind of selector matching mode we should use.
@@ -110,8 +110,8 @@ where
matching_mode: MatchingMode,
/// Input with the bloom filter used to fast-reject selectors.
pub bloom_filter: Option<&'a BloomFilter>,
- /// An optional cache to speed up nth-index-like selectors.
- pub nth_index_cache: Option<&'a mut NthIndexCache>,
+ /// A cache to speed up nth-index-like selectors.
+ pub nth_index_cache: &'a mut NthIndexCache,
/// The element which is going to match :scope pseudo-class. It can be
/// either one :scope element, or the scoping element.
///
@@ -161,7 +161,7 @@ where
pub fn new(
matching_mode: MatchingMode,
bloom_filter: Option<&'a BloomFilter>,
- nth_index_cache: Option<&'a mut NthIndexCache>,
+ nth_index_cache: &'a mut NthIndexCache,
quirks_mode: QuirksMode,
needs_selector_flags: NeedsSelectorFlags,
) -> Self {
@@ -179,7 +179,7 @@ where
pub fn new_for_visited(
matching_mode: MatchingMode,
bloom_filter: Option<&'a BloomFilter>,
- nth_index_cache: Option<&'a mut NthIndexCache>,
+ nth_index_cache: &'a mut NthIndexCache,
visited_handling: VisitedHandlingMode,
quirks_mode: QuirksMode,
needs_selector_flags: NeedsSelectorFlags,
@@ -202,6 +202,17 @@ where
}
}
+ // Grab a reference to the appropriate cache.
+ #[inline]
+ pub fn nth_index_cache(
+ &mut self,
+ is_of_type: bool,
+ is_from_end: bool,
+ selectors: &[Selector<Impl>],
+ ) -> &mut NthIndexCacheInner {
+ self.nth_index_cache.get(is_of_type, is_from_end, selectors)
+ }
+
/// Whether we're matching a nested selector.
#[inline]
pub fn is_nested(&self) -> bool {