Struct style::selector_map::SelectorMap
[−]
[src]
pub struct SelectorMap<T: 'static> { 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 other: SmallVec<[T; 1]>, pub count: usize, }
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
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.
other: SmallVec<[T; 1]>
Rules that don't have ID, class, or element selectors.
count: usize
The number of entries in this map.
Methods
impl<T: 'static> SelectorMap<T>
[src]
pub fn new() -> Self
[src]
Trivially constructs an empty SelectorMap
.
pub fn clear(&mut self)
[src]
Clears the hashmap retaining storage.
pub fn is_empty(&self) -> bool
[src]
Returns whether there are any entries in the map.
pub fn len(&self) -> usize
[src]
Returns the number of entries.
impl SelectorMap<Rule>
[src]
pub fn get_all_matching_rules<E, F>(
&self,
element: &E,
rule_hash_target: &E,
matching_rules_list: &mut ApplicableDeclarationList,
context: &mut MatchingContext<E::Impl>,
quirks_mode: QuirksMode,
flags_setter: &mut F,
cascade_level: CascadeLevel
) where
E: TElement,
F: FnMut(&E, ElementSelectorFlags),
[src]
&self,
element: &E,
rule_hash_target: &E,
matching_rules_list: &mut ApplicableDeclarationList,
context: &mut MatchingContext<E::Impl>,
quirks_mode: QuirksMode,
flags_setter: &mut F,
cascade_level: CascadeLevel
) where
E: TElement,
F: FnMut(&E, ElementSelectorFlags),
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.
impl<T: SelectorMapEntry> SelectorMap<T>
[src]
pub fn insert(
&mut self,
entry: T,
quirks_mode: QuirksMode
) -> Result<(), FailedAllocationError>
[src]
&mut self,
entry: T,
quirks_mode: QuirksMode
) -> Result<(), FailedAllocationError>
Inserts into the correct hash, trying id, class, and localname.
pub fn lookup<'a, E, F>(
&'a self,
element: E,
quirks_mode: QuirksMode,
f: F
) -> bool where
E: TElement,
F: FnMut(&'a T) -> bool,
[src]
&'a self,
element: E,
quirks_mode: QuirksMode,
f: F
) -> bool where
E: TElement,
F: FnMut(&'a T) -> bool,
Looks up entries by id, class, local name, 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
pub fn lookup_with_additional<'a, E, F>(
&'a self,
element: E,
quirks_mode: QuirksMode,
additional_id: Option<&Atom>,
additional_classes: &[Atom],
f: F
) -> bool where
E: TElement,
F: FnMut(&'a T) -> bool,
[src]
&'a self,
element: E,
quirks_mode: QuirksMode,
additional_id: Option<&Atom>,
additional_classes: &[Atom],
f: F
) -> bool where
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
impl<T: Debug + 'static> Debug for SelectorMap<T>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: 'static> MallocSizeOf for SelectorMap<T> where
T: MallocSizeOf,
[src]
T: MallocSizeOf,
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
[src]
Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself. Read more