Struct style::selector_map::SelectorMap
source · pub struct SelectorMap<T: 'static> {
pub root: SmallVec<[T; 1]>,
pub id_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>,
pub class_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>,
pub local_name_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>,
pub attribute_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>,
pub namespace_hash: PrecomputedHashMap<Namespace, SmallVec<[T; 1]>>,
pub rare_pseudo_classes: SmallVec<[T; 1]>,
pub other: SmallVec<[T; 1]>,
bucket_attributes: bool,
pub count: usize,
}
Expand description
Map element data to selector-providing objects for which the last simple selector starts with them.
e.g., “p > img” would go into the set of selectors corresponding to the element “img” “a .foo .bar.baz” would go into the set of selectors corresponding to the class “bar”
Because we match selectors right-to-left (i.e., moving up the tree from an element), we need to compare the last simple selector in the selector with the element.
So, if an element has ID “id1” and classes “foo” and “bar”, then all the rules it matches will have their last simple selector starting either with “#id1” or with “.foo” or with “.bar”.
Hence, the union of the rules keyed on each of element’s classes, ID, element name, etc. will contain the Selectors that actually match that element.
We use a 1-entry SmallVec to avoid a separate heap allocation in the case where we only have one entry, which is quite common. See measurements in:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1363789#c5
- https://bugzilla.mozilla.org/show_bug.cgi?id=681755
TODO: Tune the initial capacity of the HashMap
Fields§
§root: SmallVec<[T; 1]>
Rules that have :root
selectors.
id_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>
A hash from an ID to rules which contain that ID selector.
class_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>
A hash from a class name to rules which contain that class selector.
local_name_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>
A hash from local name to rules which contain that local name selector.
attribute_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>
A hash from attributes to rules which contain that attribute selector.
namespace_hash: PrecomputedHashMap<Namespace, SmallVec<[T; 1]>>
A hash from namespace to rules which contain that namespace selector.
rare_pseudo_classes: SmallVec<[T; 1]>
Rules for pseudo-states that are rare but have global selectors.
other: SmallVec<[T; 1]>
All other rules.
bucket_attributes: bool
Whether we should bucket by attribute names.
count: usize
The number of entries in this map.
Implementations§
source§impl<T> SelectorMap<T>
impl<T> SelectorMap<T>
sourcepub fn new_without_attribute_bucketing() -> Self
pub fn new_without_attribute_bucketing() -> Self
Trivially constructs an empty SelectorMap
, with attribute bucketing
explicitly disabled.
sourcepub fn shrink_if_needed(&mut self)
pub fn shrink_if_needed(&mut self)
Shrink the capacity of the map if needed.
source§impl SelectorMap<Rule>
impl SelectorMap<Rule>
sourcepub fn get_all_matching_rules<E>(
&self,
element: E,
rule_hash_target: E,
matching_rules_list: &mut ApplicableDeclarationList,
matching_context: &mut MatchingContext<'_, E::Impl>,
cascade_level: CascadeLevel,
cascade_data: &CascadeData,
stylist: &Stylist
)where
E: TElement,
pub fn get_all_matching_rules<E>( &self, element: E, rule_hash_target: E, matching_rules_list: &mut ApplicableDeclarationList, matching_context: &mut MatchingContext<'_, E::Impl>, cascade_level: CascadeLevel, cascade_data: &CascadeData, stylist: &Stylist )where E: TElement,
Append to rule_list
all Rules in self
that match element.
Extract matching rules as per element’s ID, classes, tag name, etc.. Sort the Rules at the end to maintain cascading order.
sourcepub(crate) fn get_matching_rules<E>(
element: E,
rules: &[Rule],
matching_rules: &mut ApplicableDeclarationList,
matching_context: &mut MatchingContext<'_, E::Impl>,
cascade_level: CascadeLevel,
cascade_data: &CascadeData,
stylist: &Stylist
)where
E: TElement,
pub(crate) fn get_matching_rules<E>( element: E, rules: &[Rule], matching_rules: &mut ApplicableDeclarationList, matching_context: &mut MatchingContext<'_, E::Impl>, cascade_level: CascadeLevel, cascade_data: &CascadeData, stylist: &Stylist )where E: TElement,
Adds rules in rules
that match element
to the matching_rules
list.
source§impl<T: SelectorMapEntry> SelectorMap<T>
impl<T: SelectorMapEntry> SelectorMap<T>
sourcepub fn insert(
&mut self,
entry: T,
quirks_mode: QuirksMode
) -> Result<(), AllocErr>
pub fn insert( &mut self, entry: T, quirks_mode: QuirksMode ) -> Result<(), AllocErr>
Inserts an entry into the correct bucket(s).
sourcepub fn lookup<'a, E, F>(
&'a self,
element: E,
quirks_mode: QuirksMode,
f: F
) -> boolwhere
E: TElement,
F: FnMut(&'a T) -> bool,
pub fn lookup<'a, E, F>( &'a self, element: E, quirks_mode: QuirksMode, f: F ) -> boolwhere E: TElement, F: FnMut(&'a T) -> bool,
Looks up entries by id, class, local name, namespace, and other (in order).
Each entry is passed to the callback, which returns true to continue iterating entries, or false to terminate the lookup.
Returns false if the callback ever returns false.
FIXME(bholley) This overlaps with SelectorMap
fn lookup_with_state<'a, E, F>( &'a self, element: E, element_state: ElementState, quirks_mode: QuirksMode, f: F ) -> boolwhere E: TElement, F: FnMut(&'a T) -> bool,
sourcepub fn lookup_with_additional<'a, E, F>(
&'a self,
element: E,
quirks_mode: QuirksMode,
additional_id: Option<&WeakAtom>,
additional_classes: &[Atom],
additional_states: ElementState,
f: F
) -> boolwhere
E: TElement,
F: FnMut(&'a T) -> bool,
pub fn lookup_with_additional<'a, E, F>( &'a self, element: E, quirks_mode: QuirksMode, additional_id: Option<&WeakAtom>, additional_classes: &[Atom], additional_states: ElementState, f: F ) -> boolwhere E: TElement, F: FnMut(&'a T) -> bool,
Performs a normal lookup, and also looks up entries for the passed-in id and classes.
Each entry is passed to the callback, which returns true to continue iterating entries, or false to terminate the lookup.
Returns false if the callback ever returns false.
Trait Implementations§
source§impl<T: Clone + 'static> Clone for SelectorMap<T>
impl<T: Clone + 'static> Clone for SelectorMap<T>
source§fn clone(&self) -> SelectorMap<T>
fn clone(&self) -> SelectorMap<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more