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

A hash from an ID to rules which contain that ID selector.

A hash from a class name to rules which contain that class selector.

A hash from local name to rules which contain that local name selector.

Rules that don't have ID, class, or element selectors.

The number of entries in this map.

Methods

impl<T: 'static> SelectorMap<T>
[src]

[src]

Trivially constructs an empty SelectorMap.

[src]

Clears the hashmap retaining storage.

[src]

Returns whether there are any entries in the map.

[src]

Returns the number of entries.

impl SelectorMap<Rule>
[src]

[src]

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]

[src]

Inserts into the correct hash, trying id, class, and localname.

[src]

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::get_all_matching_rules, but that function is extremely hot and I'd rather not rearrange it.

[src]

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]

[src]

Formats the value using the given formatter. Read more

impl<T: 'static> MallocSizeOf for SelectorMap<T> where
    T: MallocSizeOf
[src]

[src]

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself. Read more