From e030c0d96abd967e81dcfe5a0d7f759a3a3a8b69 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Sep 2017 19:03:40 +1000 Subject: [PATCH 1/2] Rename `add_size_of_children()` methods as `add_size_of()`. This makes them match `size_of` from `MallocSizeOf`. --- components/malloc_size_of/lib.rs | 4 ++-- components/style/gecko/data.rs | 4 ++-- components/style/stylist.rs | 14 +++++++------- ports/geckolib/glue.rs | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index 0e802d38610..95d3bd6335b 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -39,8 +39,8 @@ //! - If you need an additional synchronization argument, provide a function //! that is like the standard trait method, but with the extra argument. //! - If you need multiple measurements for a type, provide a function named -//! `add_size_of_children` that takes a mutable reference to a struct that -//! contains the multiple measurement fields. +//! `add_size_of` that takes a mutable reference to a struct that contains +//! the multiple measurement fields. //! - When deep measurement (via `MallocSizeOf`) cannot be implemented for a //! type, shallow measurement (via `MallocShallowSizeOf`) in combination with //! iteration can be a useful substitute. diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index 698a00282d2..2db087186ad 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -181,8 +181,8 @@ impl PerDocumentStyleDataImpl { } /// Measure heap usage. - pub fn add_size_of_children(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { - self.stylist.add_size_of_children(ops, sizes); + pub fn add_size_of(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { + self.stylist.add_size_of(ops, sizes); } } diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 5962117fbad..da17b547d38 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -174,7 +174,7 @@ struct UserAgentCascadeData { impl UserAgentCascadeData { #[cfg(feature = "gecko")] fn add_size_of(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { - self.cascade_data.add_size_of_children(ops, sizes); + self.cascade_data.add_size_of(ops, sizes); sizes.mPrecomputedPseudos += self.precomputed_pseudo_element_decls.size_of(ops); } } @@ -329,9 +329,9 @@ impl DocumentCascadeData { /// Measures heap usage. #[cfg(feature = "gecko")] - pub fn add_size_of_children(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { - self.user.add_size_of_children(ops, sizes); - self.author.add_size_of_children(ops, sizes); + pub fn add_size_of(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { + self.user.add_size_of(ops, sizes); + self.author.add_size_of(ops, sizes); } } @@ -1530,8 +1530,8 @@ impl Stylist { /// Measures heap usage. #[cfg(feature = "gecko")] - pub fn add_size_of_children(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { - self.cascade_data.add_size_of_children(ops, sizes); + pub fn add_size_of(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { + self.cascade_data.add_size_of(ops, sizes); sizes.mRuleTree += self.rule_tree.size_of(ops); // We may measure other fields in the future if DMD says it's worth it. @@ -2225,7 +2225,7 @@ impl CascadeData { /// Measures heap usage. #[cfg(feature = "gecko")] - pub fn add_size_of_children(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { + pub fn add_size_of(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) { sizes.mElementAndPseudosMaps += self.element_map.size_of(ops); for elem in self.pseudos_map.iter() { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 18f7afb224f..a72fd98c194 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -3781,7 +3781,7 @@ pub extern "C" fn Servo_StyleSet_AddSizeOfExcludingThis( malloc_enclosing_size_of.unwrap(), None); let sizes = unsafe { sizes.as_mut() }.unwrap(); - data.add_size_of_children(&mut ops, sizes); + data.add_size_of(&mut ops, sizes); } #[no_mangle] From 009150696fe354061efe3b826f2aa94456b762fb Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 21 Sep 2017 10:25:08 +1000 Subject: [PATCH 2/2] Remove some `use` statements in malloc_size_of. This file potentially uses multiple implementations of types like `Arc`, so explicit qualification makes things clearer. --- components/malloc_size_of/lib.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index 95d3bd6335b..413942e4322 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -64,8 +64,6 @@ extern crate servo_arc; extern crate smallbitvec; extern crate smallvec; -use servo_arc::Arc; -use smallvec::{Array, SmallVec}; use std::hash::{BuildHasher, Hash}; use std::ops::Range; use std::os::raw::c_void; @@ -244,7 +242,7 @@ impl MallocSizeOf for Vec { } } -impl MallocShallowSizeOf for SmallVec { +impl MallocShallowSizeOf for smallvec::SmallVec { fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { if self.spilled() { unsafe { ops.malloc_size_of(self.as_ptr()) } @@ -254,8 +252,8 @@ impl MallocShallowSizeOf for SmallVec { } } -impl MallocSizeOf for SmallVec - where A: Array, +impl MallocSizeOf for smallvec::SmallVec + where A: smallvec::Array, A::Item: MallocSizeOf { fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { @@ -348,19 +346,19 @@ impl MallocSizeOf for hashglobe::hash_map::HashMap //impl !MallocSizeOf for Arc { } //impl !MallocShallowSizeOf for Arc { } -impl MallocUnconditionalShallowSizeOf for Arc { +impl MallocUnconditionalShallowSizeOf for servo_arc::Arc { fn unconditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { unsafe { ops.malloc_size_of(self.heap_ptr()) } } } -impl MallocUnconditionalSizeOf for Arc { +impl MallocUnconditionalSizeOf for servo_arc::Arc { fn unconditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { self.unconditional_shallow_size_of(ops) + (**self).size_of(ops) } } -impl MallocConditionalShallowSizeOf for Arc { +impl MallocConditionalShallowSizeOf for servo_arc::Arc { fn conditional_shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { if ops.have_seen_ptr(self.heap_ptr()) { 0 @@ -370,7 +368,7 @@ impl MallocConditionalShallowSizeOf for Arc { } } -impl MallocConditionalSizeOf for Arc { +impl MallocConditionalSizeOf for servo_arc::Arc { fn conditional_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { if ops.have_seen_ptr(self.heap_ptr()) { 0