Skip to content

Commit

Permalink
Reduce the size of ApplicableDeclarationBlock.
Browse files Browse the repository at this point in the history
The level is a u8, so on 64-bit it packs nicely after the u32 specificity.
  • Loading branch information
bzbarsky committed Jun 8, 2017
1 parent 3616b8f commit 6601ae2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions components/style/stylist.rs
Expand Up @@ -1524,9 +1524,9 @@ impl Rule {
-> ApplicableDeclarationBlock {
ApplicableDeclarationBlock {
source: StyleSource::Style(self.style_rule.clone()),
level: level,
source_order: self.source_order,
specificity: self.specificity(),
level: level,
}
}

Expand Down Expand Up @@ -1557,12 +1557,12 @@ pub struct ApplicableDeclarationBlock {
/// The style source, either a style rule, or a property declaration block.
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
pub source: StyleSource,
/// The cascade level this applicable declaration block is in.
pub level: CascadeLevel,
/// The source order of this block.
pub source_order: usize,
/// The specificity of the selector this block is represented by.
pub specificity: u32,
/// The cascade level this applicable declaration block is in.
pub level: CascadeLevel,
}

impl ApplicableDeclarationBlock {
Expand All @@ -1574,9 +1574,9 @@ impl ApplicableDeclarationBlock {
-> Self {
ApplicableDeclarationBlock {
source: StyleSource::Declarations(declarations),
level: level,
source_order: 0,
specificity: 0,
level: level,
}
}
}
3 changes: 3 additions & 0 deletions tests/unit/stylo/size_of.rs
Expand Up @@ -10,6 +10,7 @@ use style::data::{ComputedStyle, ElementData, ElementStyles};
use style::gecko::selector_parser as real;
use style::properties::ComputedValues;
use style::rule_tree::StrongRuleNode;
use style::stylist::ApplicableDeclarationBlock;

#[test]
fn size_of_selectors_dummy_types() {
Expand All @@ -36,6 +37,8 @@ size_of_test!(test_size_of_element_data, ElementData, 56);

size_of_test!(test_size_of_property_declaration, style::properties::PropertyDeclaration, 32);

size_of_test!(test_size_of_application_declaration_block, ApplicableDeclarationBlock, 32);

// This is huge, but we allocate it on the stack and then never move it,
// we only pass `&mut SourcePropertyDeclaration` references around.
size_of_test!(test_size_of_parsed_declaration, style::properties::SourcePropertyDeclaration, 704);
Expand Down

0 comments on commit 6601ae2

Please sign in to comment.