aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-04-09 00:11:03 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-04-12 12:20:04 +0200
commitae32e4df40747c60605f64e6db1edb2e75635f08 (patch)
tree2e0c7b860c6ef4ef236b07479b27e46ebe96a065 /components
parent369acffea8effcbeaff5b3ea839a4362943b8368 (diff)
downloadservo-ae32e4df40747c60605f64e6db1edb2e75635f08.tar.gz
servo-ae32e4df40747c60605f64e6db1edb2e75635f08.zip
style: Use an explicit stack to measure rule tree memory usage.
A patch of mine that makes us measure the rule tree more often triggers this. Differential Revision: https://phabricator.services.mozilla.com/D26595
Diffstat (limited to 'components')
-rw-r--r--components/style/rule_tree/mod.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs
index 3e2696fff9b..d653b6be99d 100644
--- a/components/style/rule_tree/mod.rs
+++ b/components/style/rule_tree/mod.rs
@@ -75,8 +75,15 @@ impl Drop for RuleTree {
#[cfg(feature = "gecko")]
impl MallocSizeOf for RuleTree {
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
- let mut n = unsafe { ops.malloc_size_of(self.root.ptr()) };
- n += self.root.get().size_of(ops);
+ let mut n = 0;
+ let mut stack = SmallVec::<[_; 32]>::new();
+ stack.push(self.root.downgrade());
+
+ while let Some(node) = stack.pop() {
+ n += unsafe { ops.malloc_size_of(node.ptr()) };
+ stack.extend(unsafe { (*node.ptr()).iter_children() });
+ }
+
n
}
}
@@ -947,18 +954,6 @@ impl RuleNode {
}
}
-#[cfg(feature = "gecko")]
-impl MallocSizeOf for RuleNode {
- fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
- let mut n = 0;
- for child in self.iter_children() {
- n += unsafe { ops.malloc_size_of(child.ptr()) };
- n += unsafe { (*child.ptr()).size_of(ops) };
- }
- n
- }
-}
-
#[derive(Clone)]
struct WeakRuleNode {
p: ptr::NonNull<RuleNode>,