mirror of
https://github.com/servo/servo.git
synced 2025-08-23 14:25:33 +01:00
Box larger specified values to avoid memmove impact
This commit is contained in:
parent
abc40f61c0
commit
78afe2b8d1
26 changed files with 174 additions and 67 deletions
|
@ -231,15 +231,15 @@ mod shorthand_serialization {
|
|||
fn border_color_should_serialize_correctly() {
|
||||
let mut properties = Vec::new();
|
||||
|
||||
let red = DeclaredValue::Value(CSSColor {
|
||||
let red = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
|
||||
let blue = DeclaredValue::Value(CSSColor {
|
||||
let blue = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 0f32, green: 0f32, blue: 1f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopColor(blue.clone()));
|
||||
properties.push(PropertyDeclaration::BorderRightColor(red.clone()));
|
||||
|
@ -281,10 +281,10 @@ mod shorthand_serialization {
|
|||
|
||||
let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
|
||||
let style = DeclaredValue::Value(BorderStyle::solid);
|
||||
let color = DeclaredValue::Value(CSSColor {
|
||||
let color = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopWidth(width));
|
||||
properties.push(PropertyDeclaration::BorderTopStyle(style));
|
||||
|
@ -300,10 +300,10 @@ mod shorthand_serialization {
|
|||
|
||||
let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32)));
|
||||
let style = DeclaredValue::Initial;
|
||||
let color = DeclaredValue::Value(CSSColor {
|
||||
let color = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopWidth(width));
|
||||
properties.push(PropertyDeclaration::BorderTopStyle(style));
|
||||
|
@ -469,10 +469,10 @@ mod shorthand_serialization {
|
|||
|
||||
let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32)));
|
||||
let style = DeclaredValue::Value(Either::Second(BorderStyle::solid));
|
||||
let color = DeclaredValue::Value(CSSColor {
|
||||
let color = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
|
||||
properties.push(PropertyDeclaration::OutlineWidth(width));
|
||||
properties.push(PropertyDeclaration::OutlineStyle(style));
|
||||
|
@ -504,10 +504,10 @@ mod shorthand_serialization {
|
|||
|
||||
let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32)));
|
||||
let style = DeclaredValue::Initial;
|
||||
let color = DeclaredValue::Value(CSSColor {
|
||||
let color = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
properties.push(PropertyDeclaration::OutlineWidth(width));
|
||||
properties.push(PropertyDeclaration::OutlineStyle(style));
|
||||
properties.push(PropertyDeclaration::OutlineColor(color));
|
||||
|
@ -522,10 +522,10 @@ mod shorthand_serialization {
|
|||
|
||||
let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32)));
|
||||
let style = DeclaredValue::Value(Either::First(Auto));
|
||||
let color = DeclaredValue::Value(CSSColor {
|
||||
let color = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
properties.push(PropertyDeclaration::OutlineWidth(width));
|
||||
properties.push(PropertyDeclaration::OutlineStyle(style));
|
||||
properties.push(PropertyDeclaration::OutlineColor(color));
|
||||
|
@ -730,10 +730,10 @@ mod shorthand_serialization {
|
|||
fn background_should_serialize_all_available_properties_when_specified() {
|
||||
let mut properties = Vec::new();
|
||||
|
||||
let color = DeclaredValue::Value(CSSColor {
|
||||
let color = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
|
||||
let position_x = single_vec_value_typedef!(position_x,
|
||||
HorizontalPosition {
|
||||
|
@ -790,10 +790,10 @@ mod shorthand_serialization {
|
|||
fn background_should_combine_origin_and_clip_properties_when_equal() {
|
||||
let mut properties = Vec::new();
|
||||
|
||||
let color = DeclaredValue::Value(CSSColor {
|
||||
let color = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
|
||||
let position_x = single_vec_value_typedef!(position_x,
|
||||
HorizontalPosition {
|
||||
|
@ -849,10 +849,10 @@ mod shorthand_serialization {
|
|||
fn background_should_always_print_color_and_url_and_repeat_and_attachment_and_position() {
|
||||
let mut properties = Vec::new();
|
||||
|
||||
let color = DeclaredValue::Value(CSSColor {
|
||||
let color = DeclaredValue::Value(Box::new(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
|
||||
authored: None
|
||||
});
|
||||
}));
|
||||
|
||||
let position_x = single_vec_value_typedef!(position_x,
|
||||
HorizontalPosition {
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::mem::size_of;
|
||||
use style::properties::PropertyDeclaration;
|
||||
use style::properties::{PropertyDeclaration, specified_value_sizes};
|
||||
|
||||
#[test]
|
||||
fn size_of_property_declaration() {
|
||||
let old = 240;
|
||||
let old = 96;
|
||||
let new = size_of::<PropertyDeclaration>();
|
||||
if new < old {
|
||||
panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \
|
||||
|
@ -22,3 +22,23 @@ fn size_of_property_declaration() {
|
|||
old, new)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn size_of_specified_values() {
|
||||
let threshold = 40;
|
||||
let longhands = specified_value_sizes();
|
||||
|
||||
for specified_value in longhands {
|
||||
if specified_value.1 >= threshold && !specified_value.2 {
|
||||
panic!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \
|
||||
currently {}. SpecifiedValues are affect size of PropertyDeclaration enum and \
|
||||
increasing the size may dramatically affect our memory footprint. Please consider \
|
||||
using `boxed=\"True\"` in this longhand.",
|
||||
specified_value.0, specified_value.1, threshold)
|
||||
} else if specified_value.1 < threshold && specified_value.2 {
|
||||
panic!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \
|
||||
The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.",
|
||||
specified_value.0, specified_value.1, threshold)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,12 +183,12 @@ fn test_parse_stylesheet() {
|
|||
block: Arc::new(RwLock::new(PropertyDeclarationBlock {
|
||||
declarations: vec![
|
||||
(PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
|
||||
longhands::background_color::SpecifiedValue {
|
||||
Box::new(longhands::background_color::SpecifiedValue {
|
||||
authored: Some("blue".to_owned()),
|
||||
parsed: cssparser::Color::RGBA(cssparser::RGBA {
|
||||
red: 0., green: 0., blue: 1., alpha: 1.
|
||||
}),
|
||||
}
|
||||
})
|
||||
)),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundPositionX(DeclaredValue::Value(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue