mirror of
https://github.com/servo/servo.git
synced 2025-08-20 12:55:33 +01:00
Introduce and start using the MallocSizeOf trait.
MallocSizeOf is similar to the existing HeapSizeOf trait from the heapsize crate. The only difference is that MallocSizeOf's malloc_size_of_children() function takes an additional MallocSizeOfFn argument, which is used to measure heap blocks. This extra argument makes MallocSizeOf match how Gecko's memory measurements work, and is required for Stylo to integrate with DMD. The patch also introduces a second trait, MallocSizeOfWithGuard, which is much the same as MallocSizeOf, but with a |guard| argument for the global style lock. Finally, the patch uses the new traits to measure a small amount of Stylo's memory usage.
This commit is contained in:
parent
4ec2e8b4c5
commit
6d5b1242db
5 changed files with 139 additions and 5 deletions
|
@ -16,6 +16,7 @@ use std::fmt;
|
|||
use std::slice::Iter;
|
||||
use style_traits::ToCss;
|
||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
use stylesheets::{MallocSizeOf, MallocSizeOfFn};
|
||||
use super::*;
|
||||
#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValueMap;
|
||||
|
||||
|
@ -46,6 +47,12 @@ pub enum Importance {
|
|||
Important,
|
||||
}
|
||||
|
||||
impl MallocSizeOf for Importance {
|
||||
fn malloc_size_of_children(&self, _malloc_size_of: MallocSizeOfFn) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl Importance {
|
||||
/// Return whether this is an important declaration.
|
||||
pub fn important(self) -> bool {
|
||||
|
@ -70,6 +77,12 @@ pub struct PropertyDeclarationBlock {
|
|||
longhands: LonghandIdSet,
|
||||
}
|
||||
|
||||
impl MallocSizeOf for PropertyDeclarationBlock {
|
||||
fn malloc_size_of_children(&self, malloc_size_of: MallocSizeOfFn) -> usize {
|
||||
self.declarations.malloc_size_of_children(malloc_size_of)
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator for PropertyDeclaration to be generated from PropertyDeclarationBlock.
|
||||
#[derive(Clone)]
|
||||
pub struct PropertyDeclarationIterator<'a> {
|
||||
|
|
|
@ -35,7 +35,7 @@ use properties::animated_properties::TransitionProperty;
|
|||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use style_traits::{HasViewportPercentage, ToCss};
|
||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
use stylesheets::{CssRuleType, MallocSizeOf, MallocSizeOfFn, Origin, UrlExtraData};
|
||||
#[cfg(feature = "servo")] use values::Either;
|
||||
use values::computed;
|
||||
use cascade_info::CascadeInfo;
|
||||
|
@ -1171,6 +1171,14 @@ impl ToCss for PropertyDeclaration {
|
|||
% endif
|
||||
</%def>
|
||||
|
||||
impl MallocSizeOf for PropertyDeclaration {
|
||||
fn malloc_size_of_children(&self, _malloc_size_of: MallocSizeOfFn) -> usize {
|
||||
// The variants of PropertyDeclaration mostly (entirely?) contain
|
||||
// scalars, so this is reasonable.
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyDeclaration {
|
||||
/// Given a property declaration, return the property declaration id.
|
||||
pub fn id(&self) -> PropertyDeclarationId {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue