style: Make stylesheet invalidation faster.

This fixes performance issues when there's a massive number of rules and
a massive DOM.

Instead of going through all rules for all the DOM, we now look stuff in
hashmaps.

Differential Revision: https://phabricator.services.mozilla.com/D83506
This commit is contained in:
Emilio Cobos Álvarez 2020-07-20 07:40:17 +00:00
parent 5752e4a3a2
commit 780beace00
2 changed files with 197 additions and 122 deletions

View file

@ -620,13 +620,20 @@ pub struct MaybeCaseInsensitiveHashMap<K: PrecomputedHash + Hash + Eq, V: 'stati
PrecomputedHashMap<K, V>,
);
impl<V: 'static> Default for MaybeCaseInsensitiveHashMap<Atom, V> {
#[inline]
fn default() -> Self {
MaybeCaseInsensitiveHashMap(PrecomputedHashMap::default())
}
}
// FIXME(Manishearth) the 'static bound can be removed when
// our HashMap fork (hashglobe) is able to use NonZero,
// or when stdlib gets fallible collections
impl<V: 'static> MaybeCaseInsensitiveHashMap<Atom, V> {
/// Empty map
pub fn new() -> Self {
MaybeCaseInsensitiveHashMap(PrecomputedHashMap::default())
Self::default()
}
/// HashMap::try_entry
@ -641,6 +648,12 @@ impl<V: 'static> MaybeCaseInsensitiveHashMap<Atom, V> {
self.0.try_entry(key)
}
/// HashMap::is_empty
#[inline]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
/// HashMap::iter
pub fn iter(&self) -> hash_map::Iter<Atom, V> {
self.0.iter()