mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Measure the stylist during memory reporting.
This commit is contained in:
parent
f648e12935
commit
d880efcab3
14 changed files with 356 additions and 28 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue