mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
style: Measure heap allocations hanging off selector components.
Bug: 1475191 Reviewed-by: emilio MozReview-Commit-ID: D7vZQ7v8owS
This commit is contained in:
parent
dd277be487
commit
a41127152b
5 changed files with 89 additions and 16 deletions
|
@ -693,6 +693,90 @@ impl MallocSizeOf for selectors::parser::AncestorHashes {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Impl: selectors::parser::SelectorImpl> MallocSizeOf
|
||||
for selectors::parser::Selector<Impl>
|
||||
where
|
||||
Impl::NonTSPseudoClass: MallocSizeOf,
|
||||
Impl::PseudoElement: MallocSizeOf,
|
||||
{
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
let mut n = 0;
|
||||
|
||||
// It's OK to measure this ThinArc directly because it's the
|
||||
// "primary" reference. (The secondary references are on the
|
||||
// Stylist.)
|
||||
n += unsafe { ops.malloc_size_of(self.thin_arc_heap_ptr()) };
|
||||
for component in self.iter_raw_match_order() {
|
||||
n += component.size_of(ops);
|
||||
}
|
||||
|
||||
n
|
||||
}
|
||||
}
|
||||
|
||||
impl<Impl: selectors::parser::SelectorImpl> MallocSizeOf
|
||||
for selectors::parser::Component<Impl>
|
||||
where
|
||||
Impl::NonTSPseudoClass: MallocSizeOf,
|
||||
Impl::PseudoElement: MallocSizeOf,
|
||||
{
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
use selectors::parser::Component;
|
||||
|
||||
match self {
|
||||
Component::AttributeOther(ref attr_selector) => {
|
||||
attr_selector.size_of(ops)
|
||||
}
|
||||
Component::Negation(ref components) => {
|
||||
components.size_of(ops)
|
||||
}
|
||||
Component::NonTSPseudoClass(ref pseudo) => {
|
||||
(*pseudo).size_of(ops)
|
||||
}
|
||||
Component::Slotted(ref selector) |
|
||||
Component::Host(Some(ref selector)) => {
|
||||
selector.size_of(ops)
|
||||
}
|
||||
Component::PseudoElement(ref pseudo) => {
|
||||
(*pseudo).size_of(ops)
|
||||
}
|
||||
Component::Combinator(..) |
|
||||
Component::ExplicitAnyNamespace |
|
||||
Component::ExplicitNoNamespace |
|
||||
Component::DefaultNamespace(..) |
|
||||
Component::Namespace(..) |
|
||||
Component::ExplicitUniversalType |
|
||||
Component::LocalName(..) |
|
||||
Component::ID(..) |
|
||||
Component::Class(..) |
|
||||
Component::AttributeInNoNamespaceExists { .. } |
|
||||
Component::AttributeInNoNamespace { .. } |
|
||||
Component::FirstChild |
|
||||
Component::LastChild |
|
||||
Component::OnlyChild |
|
||||
Component::Root |
|
||||
Component::Empty |
|
||||
Component::Scope |
|
||||
Component::NthChild(..) |
|
||||
Component::NthLastChild(..) |
|
||||
Component::NthOfType(..) |
|
||||
Component::NthLastOfType(..) |
|
||||
Component::FirstOfType |
|
||||
Component::LastOfType |
|
||||
Component::OnlyOfType |
|
||||
Component::Host(None) => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Impl: selectors::parser::SelectorImpl> MallocSizeOf
|
||||
for selectors::attr::AttrSelectorWithNamespace<Impl>
|
||||
{
|
||||
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl MallocSizeOf for Void {
|
||||
#[inline]
|
||||
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/// Gecko's pseudo-element definition.
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq)]
|
||||
pub enum PseudoElement {
|
||||
% for pseudo in PSEUDOS:
|
||||
/// ${pseudo.value}
|
||||
|
|
|
@ -40,7 +40,7 @@ macro_rules! pseudo_class_name {
|
|||
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
||||
string: [$(($s_css:expr, $s_name:ident, $s_gecko_type:tt, $s_state:tt, $s_flags:tt),)*]) => {
|
||||
/// Our representation of a non tree-structural pseudo-class.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)]
|
||||
pub enum NonTSPseudoClass {
|
||||
$(
|
||||
#[doc = $css]
|
||||
|
|
|
@ -172,7 +172,7 @@ impl<T> PerPseudoElementMap<T> {
|
|||
}
|
||||
|
||||
/// Values for the :dir() pseudo class
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)]
|
||||
pub enum Direction {
|
||||
/// left-to-right semantic directionality
|
||||
Ltr,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use cssparser::SourceLocation;
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps};
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::MallocUnconditionalShallowSizeOf;
|
||||
use properties::PropertyDeclarationBlock;
|
||||
|
@ -50,20 +50,9 @@ impl StyleRule {
|
|||
#[cfg(feature = "gecko")]
|
||||
pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
|
||||
let mut n = 0;
|
||||
|
||||
// We may add measurement of things hanging off the embedded Components
|
||||
// later.
|
||||
n += self.selectors.0.shallow_size_of(ops);
|
||||
for selector in self.selectors.0.iter() {
|
||||
// It's safe to measure this ThinArc directly because it's the
|
||||
// "primary" reference. (The secondary references are on the
|
||||
// Stylist.)
|
||||
n += unsafe { ops.malloc_size_of(selector.thin_arc_heap_ptr()) };
|
||||
}
|
||||
|
||||
n += self.selectors.0.size_of(ops);
|
||||
n += self.block.unconditional_shallow_size_of(ops) +
|
||||
self.block.read_with(guard).size_of(ops);
|
||||
|
||||
n
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue