Measure the stylist during memory reporting.

This commit is contained in:
Nicholas Nethercote 2017-09-05 15:11:18 +10:00 committed by Emilio Cobos Álvarez
parent f648e12935
commit d880efcab3
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
14 changed files with 356 additions and 28 deletions

View file

@ -19,6 +19,8 @@ use selectors::matching::{matches_selector, MatchingContext, ElementSelectorFlag
use selectors::parser::{Component, Combinator, SelectorIter};
use smallvec::{SmallVec, VecLike};
use std::hash::{BuildHasherDefault, Hash, Hasher};
#[cfg(feature = "gecko")]
use stylesheets::{MallocEnclosingSizeOfFn, MallocSizeOfHash};
use stylist::Rule;
/// A hasher implementation that doesn't hash anything, because it expects its
@ -144,6 +146,22 @@ impl<T: 'static> SelectorMap<T> {
pub fn len(&self) -> usize {
self.count
}
/// Measures heap usage.
#[cfg(feature = "gecko")]
pub fn malloc_size_of_children(&self, malloc_enclosing_size_of: MallocEnclosingSizeOfFn)
-> usize {
// Currently we measure the HashMap storage, but not things pointed to
// by keys and values.
let mut n = 0;
n += self.id_hash.malloc_shallow_size_of_hash(malloc_enclosing_size_of);
n += self.class_hash.malloc_shallow_size_of_hash(malloc_enclosing_size_of);
n += self.local_name_hash.malloc_shallow_size_of_hash(malloc_enclosing_size_of);
// We may measure other fields in the future if DMD says it's worth it.
n
}
}
impl SelectorMap<Rule> {
@ -502,3 +520,14 @@ impl<V: 'static> MaybeCaseInsensitiveHashMap<Atom, V> {
}
}
}
#[cfg(feature = "gecko")]
impl<K, V> MallocSizeOfHash for MaybeCaseInsensitiveHashMap<K, V>
where K: PrecomputedHash + Eq + Hash
{
fn malloc_shallow_size_of_hash(&self, malloc_enclosing_size_of: MallocEnclosingSizeOfFn)
-> usize {
self.0.malloc_shallow_size_of_hash(malloc_enclosing_size_of)
}
}