mirror of
https://github.com/servo/servo.git
synced 2025-08-17 11:25:35 +01:00
Shrink ElementData by moving pseudo count to type
`ElementStyles` holds an optional list of values for each eager pseudo-element. However, the type was declared as a slice instead of a fixed size array, so an extra 8 bytes were being allocated to hold the size, even though it never changes. Moving the constant size into the type reduces `ElementStyles` and `ElementData` by 8 bytes. MozReview-Commit-ID: GaO6DKFxUMo
This commit is contained in:
parent
2b5c56e6a8
commit
87c51bd8bf
2 changed files with 21 additions and 5 deletions
|
@ -100,8 +100,24 @@ impl RestyleData {
|
|||
|
||||
/// A list of styles for eagerly-cascaded pseudo-elements.
|
||||
/// Lazily-allocated.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct EagerPseudoStyles(pub Option<Box<[Option<Arc<ComputedValues>>]>>);
|
||||
#[derive(Debug)]
|
||||
pub struct EagerPseudoStyles(pub Option<Box<[Option<Arc<ComputedValues>>; EAGER_PSEUDO_COUNT]>>);
|
||||
|
||||
// Manually implement `Clone` here because the derived impl of `Clone` for
|
||||
// array types assumes the value inside is `Copy`.
|
||||
impl Clone for EagerPseudoStyles {
|
||||
fn clone(&self) -> Self {
|
||||
if self.0.is_none() {
|
||||
return EagerPseudoStyles(None)
|
||||
}
|
||||
let self_values = self.0.as_ref().unwrap();
|
||||
let mut values: [Option<Arc<ComputedValues>>; EAGER_PSEUDO_COUNT] = Default::default();
|
||||
for i in 0..EAGER_PSEUDO_COUNT {
|
||||
values[i] = self_values[i].clone();
|
||||
}
|
||||
EagerPseudoStyles(Some(Box::new(values)))
|
||||
}
|
||||
}
|
||||
|
||||
impl EagerPseudoStyles {
|
||||
/// Returns whether there are any pseudo styles.
|
||||
|
@ -129,7 +145,7 @@ impl EagerPseudoStyles {
|
|||
/// Sets the style for the eager pseudo.
|
||||
pub fn set(&mut self, pseudo: &PseudoElement, value: Arc<ComputedValues>) {
|
||||
if self.0.is_none() {
|
||||
self.0 = Some(vec![None; EAGER_PSEUDO_COUNT].into_boxed_slice());
|
||||
self.0 = Some(Box::new(Default::default()));
|
||||
}
|
||||
self.0.as_mut().unwrap()[pseudo.eager_index()] = Some(value);
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ size_of_test!(test_size_of_rule, style::stylist::Rule, 32);
|
|||
size_of_test!(test_size_of_option_arc_cv, Option<Arc<ComputedValues>>, 8);
|
||||
size_of_test!(test_size_of_option_rule_node, Option<StrongRuleNode>, 8);
|
||||
|
||||
size_of_test!(test_size_of_element_styles, ElementStyles, 24);
|
||||
size_of_test!(test_size_of_element_styles, ElementStyles, 16);
|
||||
size_of_test!(test_size_of_restyle_data, RestyleData, 8);
|
||||
size_of_test!(test_size_of_element_data, ElementData, 32);
|
||||
size_of_test!(test_size_of_element_data, ElementData, 24);
|
||||
|
||||
size_of_test!(test_size_of_property_declaration, style::properties::PropertyDeclaration, 32);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue