From 97dd3a1b08596037d51be5d6c7a5bdaba48470d9 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 17 Mar 2017 16:37:43 -0700 Subject: [PATCH] Box more specified values to bring SpecifiedValue/PropertyDeclaration sizes down to 24/32 bytes. MozReview-Commit-ID: xstAfjVQqi --- components/script/dom/element.rs | 8 +-- .../style/properties/longhand/border.mako.rs | 5 +- .../style/properties/longhand/box.mako.rs | 3 +- .../style/properties/longhand/column.mako.rs | 4 +- .../properties/longhand/counters.mako.rs | 3 +- .../longhand/inherited_text.mako.rs | 8 +-- .../style/properties/longhand/outline.mako.rs | 1 + .../properties/longhand/pointing.mako.rs | 4 +- .../style/properties/properties.mako.rs | 4 +- ports/geckolib/glue.rs | 8 +-- tests/unit/style/properties/serialization.rs | 52 +++++++++---------- tests/unit/style/properties/viewport.rs | 8 +-- 12 files changed, 58 insertions(+), 50 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 3c94ca21339..8e13716fa9d 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -623,13 +623,13 @@ impl LayoutElementHelpers for LayoutJS { if let Some(border) = border { let width_value = specified::BorderWidth::from_length(specified::Length::from_px(border as f32)); hints.push(from_declaration( - PropertyDeclaration::BorderTopWidth(width_value.clone()))); + PropertyDeclaration::BorderTopWidth(Box::new(width_value.clone())))); hints.push(from_declaration( - PropertyDeclaration::BorderLeftWidth(width_value.clone()))); + PropertyDeclaration::BorderLeftWidth(Box::new(width_value.clone())))); hints.push(from_declaration( - PropertyDeclaration::BorderBottomWidth(width_value.clone()))); + PropertyDeclaration::BorderBottomWidth(Box::new(width_value.clone())))); hints.push(from_declaration( - PropertyDeclaration::BorderRightWidth(width_value))); + PropertyDeclaration::BorderRightWidth(Box::new(width_value)))); } } diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index 9594ac32127..ab6abd844d1 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -36,7 +36,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style', "none solid double dotted dashed hidden groove ridge inset outset"), type="::values::specified::BorderStyle")} % for side in ALL_SIDES: - <%helpers:longhand name="border-${side[0]}-width" animatable="True" logical="${side[1]}" + <%helpers:longhand name="border-${side[0]}-width" boxed="True" animatable="True" logical="${side[1]}" alias="${maybe_moz_logical_alias(product, side, '-moz-border-%s-width')}" spec="${maybe_logical_spec(side, 'width')}"> use app_units::Au; @@ -69,6 +69,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style', "computed::BorderRadiusSize::zero()", "parse", extra_prefixes="webkit", spec="https://drafts.csswg.org/css-backgrounds/#border-%s-radius" % corner, + boxed=True, animatable=True)} % endfor @@ -556,7 +557,7 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box", } -<%helpers:longhand name="border-image-slice" animatable="False" +<%helpers:longhand name="border-image-slice" boxed="True" animatable="False" spec="https://drafts.csswg.org/css-backgrounds/#border-image-slice"> use std::fmt; use style_traits::ToCss; diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 803e766eaee..26aab0498b8 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -1709,10 +1709,11 @@ ${helpers.predefined_type("perspective", gecko_ffi_name="mChildPerspective", spec="https://drafts.csswg.org/css-transforms/#perspective", extra_prefixes="moz webkit", + boxed=True, animatable=True)} // FIXME: This prop should be animatable -<%helpers:longhand name="perspective-origin" animatable="False" extra_prefixes="moz webkit" +<%helpers:longhand name="perspective-origin" boxed="True" animatable="False" extra_prefixes="moz webkit" spec="https://drafts.csswg.org/css-transforms/#perspective-origin-property"> use std::fmt; use style_traits::ToCss; diff --git a/components/style/properties/longhand/column.mako.rs b/components/style/properties/longhand/column.mako.rs index 1b900a7f55d..c0d6d51c4a7 100644 --- a/components/style/properties/longhand/column.mako.rs +++ b/components/style/properties/longhand/column.mako.rs @@ -13,6 +13,7 @@ ${helpers.predefined_type("column-width", initial_specified_value="Either::Second(Auto)", parse_method="parse_non_negative_length", extra_prefixes="moz", + boxed=True, animatable=False, experimental=True, spec="https://drafts.csswg.org/css-multicol/#propdef-column-width")} @@ -35,6 +36,7 @@ ${helpers.predefined_type("column-gap", parse_method='parse_non_negative_length', extra_prefixes="moz", experimental=True, + boxed=True, animatable=False, spec="https://drafts.csswg.org/css-multicol/#propdef-column-gap")} @@ -43,7 +45,7 @@ ${helpers.single_keyword("column-fill", "balance auto", extra_prefixes="moz", spec="https://drafts.csswg.org/css-multicol/#propdef-column-fill")} // https://drafts.csswg.org/css-multicol-1/#propdef-column-rule-width -<%helpers:longhand name="column-rule-width" products="gecko" animatable="True" extra_prefixes="moz" +<%helpers:longhand name="column-rule-width" products="gecko" boxed="True" animatable="True" extra_prefixes="moz" spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width"> use app_units::Au; use std::fmt; diff --git a/components/style/properties/longhand/counters.mako.rs b/components/style/properties/longhand/counters.mako.rs index 8eec5fbb8b2..f6b8173c610 100644 --- a/components/style/properties/longhand/counters.mako.rs +++ b/components/style/properties/longhand/counters.mako.rs @@ -6,7 +6,8 @@ <% data.new_style_struct("Counters", inherited=False, gecko_name="Content") %> -<%helpers:longhand name="content" animatable="False" spec="https://drafts.csswg.org/css-content/#propdef-content"> +<%helpers:longhand name="content" boxed="True" animatable="False" + spec="https://drafts.csswg.org/css-content/#propdef-content"> use cssparser::Token; use std::ascii::AsciiExt; use values::computed::ComputedValueAsSpecified; diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 145b0e61ab7..1e3a2ea7024 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -308,7 +308,7 @@ ${helpers.single_keyword("text-align-last", // FIXME: This prop should be animatable. -<%helpers:longhand name="letter-spacing" animatable="False" +<%helpers:longhand name="letter-spacing" boxed="True" animatable="False" spec="https://drafts.csswg.org/css-text/#propdef-letter-spacing"> use std::fmt; use style_traits::ToCss; @@ -811,7 +811,7 @@ ${helpers.single_keyword("text-align-last", } -<%helpers:longhand name="text-emphasis-style" products="gecko" need_clone="True" animatable="False" +<%helpers:longhand name="text-emphasis-style" products="gecko" need_clone="True" boxed="True" animatable="False" spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style"> use computed_values::writing_mode::T as writing_mode; use std::fmt; @@ -1081,7 +1081,7 @@ ${helpers.predefined_type( "-moz-tab-size", "LengthOrNumber", "::values::Either::Second(8.0)", "parse_non_negative", - products="gecko", animatable=False, + products="gecko", boxed=True, animatable=False, spec="https://drafts.csswg.org/css-text-3/#tab-size-property")} @@ -1102,7 +1102,7 @@ ${helpers.predefined_type( complex_color=True, need_clone=True, spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")} -<%helpers:longhand products="gecko" name="-webkit-text-stroke-width" animatable="False" +<%helpers:longhand products="gecko" name="-webkit-text-stroke-width" boxed="True" animatable="False" spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width"> use app_units::Au; use std::fmt; diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs index a599c436174..8372943bc81 100644 --- a/components/style/properties/longhand/outline.mako.rs +++ b/components/style/properties/longhand/outline.mako.rs @@ -122,6 +122,7 @@ ${helpers.predefined_type("outline-color", "CSSColor", "computed::CSSColor::Curr ${helpers.predefined_type("-moz-outline-radius-" + corner, "BorderRadiusSize", "computed::BorderRadiusSize::zero()", "parse", products="gecko", + boxed=True, animatable=False, spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-outline-radius)")} % endfor diff --git a/components/style/properties/longhand/pointing.mako.rs b/components/style/properties/longhand/pointing.mako.rs index e3f00d333f9..49fee4369e5 100644 --- a/components/style/properties/longhand/pointing.mako.rs +++ b/components/style/properties/longhand/pointing.mako.rs @@ -6,7 +6,8 @@ <% data.new_style_struct("Pointing", inherited=True, gecko_name="UserInterface") %> -<%helpers:longhand name="cursor" animatable="False" spec="https://drafts.csswg.org/css-ui/#cursor"> +<%helpers:longhand name="cursor" boxed="${product == 'gecko'}" animatable="False" + spec="https://drafts.csswg.org/css-ui/#cursor"> pub use self::computed_value::T as SpecifiedValue; use values::HasViewportPercentage; use values::computed::ComputedValueAsSpecified; @@ -176,4 +177,5 @@ ${helpers.predefined_type("caret-color", "Either::Second(Auto)", spec="https://drafts.csswg.org/css-ui/#caret-color", animatable="True", + boxed=True, products="gecko")} diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 24e0308489e..7b81b9ae594 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2451,7 +2451,7 @@ macro_rules! longhand_properties_idents { pub fn test_size_of_property_declaration() { use std::mem::size_of; - let old = 40; + let old = 32; let new = size_of::(); if new < old { panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \ @@ -2471,7 +2471,7 @@ pub fn test_size_of_property_declaration() { #[cfg(feature = "testing")] pub fn test_size_of_specified_values() { use std::mem::size_of; - let threshold = 32; + let threshold = 24; let mut longhands = vec![]; % for property in data.longhands: diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index e2426edd07a..16d8b0c9f36 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1114,10 +1114,10 @@ pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(declarations: let prop = match_wrap_declared! { long, Height => nocalc.into(), Width => nocalc.into(), - BorderTopWidth => BorderWidth::Width(nocalc.into()), - BorderRightWidth => BorderWidth::Width(nocalc.into()), - BorderBottomWidth => BorderWidth::Width(nocalc.into()), - BorderLeftWidth => BorderWidth::Width(nocalc.into()), + BorderTopWidth => Box::new(BorderWidth::Width(nocalc.into())), + BorderRightWidth => Box::new(BorderWidth::Width(nocalc.into())), + BorderBottomWidth => Box::new(BorderWidth::Width(nocalc.into())), + BorderLeftWidth => Box::new(BorderWidth::Width(nocalc.into())), MarginTop => nocalc.into(), MarginRight => nocalc.into(), MarginBottom => nocalc.into(), diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 3bf2102a7ed..d1dc87ce011 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -237,10 +237,10 @@ mod shorthand_serialization { let px_30 = BorderWidth::from_length(Length::from_px(30f32)); let px_10 = BorderWidth::from_length(Length::from_px(10f32)); - properties.push(PropertyDeclaration::BorderTopWidth(px_30.clone())); - properties.push(PropertyDeclaration::BorderRightWidth(px_30.clone())); - properties.push(PropertyDeclaration::BorderBottomWidth(px_30.clone())); - properties.push(PropertyDeclaration::BorderLeftWidth(px_10.clone())); + properties.push(PropertyDeclaration::BorderTopWidth(Box::new(px_30.clone()))); + properties.push(PropertyDeclaration::BorderRightWidth(Box::new(px_30.clone()))); + properties.push(PropertyDeclaration::BorderBottomWidth(Box::new(px_30.clone()))); + properties.push(PropertyDeclaration::BorderLeftWidth(Box::new(px_10.clone()))); let blue = CSSColor { parsed: ComputedColor::RGBA(RGBA::new(0, 0, 255, 255)), @@ -270,10 +270,10 @@ mod shorthand_serialization { let px_30 = BorderWidth::from_length(Length::from_px(30f32)); - properties.push(PropertyDeclaration::BorderTopWidth(px_30.clone())); - properties.push(PropertyDeclaration::BorderRightWidth(px_30.clone())); - properties.push(PropertyDeclaration::BorderBottomWidth(px_30.clone())); - properties.push(PropertyDeclaration::BorderLeftWidth(px_30.clone())); + properties.push(PropertyDeclaration::BorderTopWidth(Box::new(px_30.clone()))); + properties.push(PropertyDeclaration::BorderRightWidth(Box::new(px_30.clone()))); + properties.push(PropertyDeclaration::BorderBottomWidth(Box::new(px_30.clone()))); + properties.push(PropertyDeclaration::BorderLeftWidth(Box::new(px_30.clone()))); let blue = CSSColor { parsed: ComputedColor::RGBA(RGBA::new(0, 0, 255, 255)), @@ -314,10 +314,10 @@ mod shorthand_serialization { let right_px = BorderWidth::from_length(Length::from_px(15f32)); let left_px = BorderWidth::from_length(Length::from_px(15f32)); - properties.push(PropertyDeclaration::BorderTopWidth(top_px)); - properties.push(PropertyDeclaration::BorderRightWidth(right_px)); - properties.push(PropertyDeclaration::BorderBottomWidth(bottom_px)); - properties.push(PropertyDeclaration::BorderLeftWidth(left_px)); + properties.push(PropertyDeclaration::BorderTopWidth(Box::new(top_px))); + properties.push(PropertyDeclaration::BorderRightWidth(Box::new(right_px))); + properties.push(PropertyDeclaration::BorderBottomWidth(Box::new(bottom_px))); + properties.push(PropertyDeclaration::BorderLeftWidth(Box::new(left_px))); let serialization = shorthand_properties_to_string(properties); assert_eq!(serialization, "border-width: 10px 15px;"); @@ -332,10 +332,10 @@ mod shorthand_serialization { let bottom_px = BorderWidth::Thick; let left_px = BorderWidth::from_length(Length::from_px(15f32)); - properties.push(PropertyDeclaration::BorderTopWidth(top_px)); - properties.push(PropertyDeclaration::BorderRightWidth(right_px)); - properties.push(PropertyDeclaration::BorderBottomWidth(bottom_px)); - properties.push(PropertyDeclaration::BorderLeftWidth(left_px)); + properties.push(PropertyDeclaration::BorderTopWidth(Box::new(top_px))); + properties.push(PropertyDeclaration::BorderRightWidth(Box::new(right_px))); + properties.push(PropertyDeclaration::BorderBottomWidth(Box::new(bottom_px))); + properties.push(PropertyDeclaration::BorderLeftWidth(Box::new(left_px))); let serialization = shorthand_properties_to_string(properties); assert_eq!(serialization, "border-width: thin medium thick 15px;"); @@ -400,7 +400,7 @@ mod shorthand_serialization { authored: None }; - properties.push(PropertyDeclaration::BorderTopWidth(width)); + properties.push(PropertyDeclaration::BorderTopWidth(Box::new(width))); properties.push(PropertyDeclaration::BorderTopStyle(style)); properties.push(PropertyDeclaration::BorderTopColor(color)); @@ -418,7 +418,7 @@ mod shorthand_serialization { fn border_top_should_serialize_correctly() { let mut properties = Vec::new(); let (width, style, color) = get_border_property_values(); - properties.push(PropertyDeclaration::BorderTopWidth(width)); + properties.push(PropertyDeclaration::BorderTopWidth(Box::new(width))); properties.push(PropertyDeclaration::BorderTopStyle(style)); properties.push(PropertyDeclaration::BorderTopColor(color)); @@ -430,7 +430,7 @@ mod shorthand_serialization { fn border_right_should_serialize_correctly() { let mut properties = Vec::new(); let (width, style, color) = get_border_property_values(); - properties.push(PropertyDeclaration::BorderRightWidth(width)); + properties.push(PropertyDeclaration::BorderRightWidth(Box::new(width))); properties.push(PropertyDeclaration::BorderRightStyle(style)); properties.push(PropertyDeclaration::BorderRightColor(color)); @@ -442,7 +442,7 @@ mod shorthand_serialization { fn border_bottom_should_serialize_correctly() { let mut properties = Vec::new(); let (width, style, color) = get_border_property_values(); - properties.push(PropertyDeclaration::BorderBottomWidth(width)); + properties.push(PropertyDeclaration::BorderBottomWidth(Box::new(width))); properties.push(PropertyDeclaration::BorderBottomStyle(style)); properties.push(PropertyDeclaration::BorderBottomColor(color)); @@ -454,7 +454,7 @@ mod shorthand_serialization { fn border_left_should_serialize_correctly() { let mut properties = Vec::new(); let (width, style, color) = get_border_property_values(); - properties.push(PropertyDeclaration::BorderLeftWidth(width)); + properties.push(PropertyDeclaration::BorderLeftWidth(Box::new(width))); properties.push(PropertyDeclaration::BorderLeftStyle(style)); properties.push(PropertyDeclaration::BorderLeftColor(color)); @@ -467,19 +467,19 @@ mod shorthand_serialization { let mut properties = Vec::new(); let (width, style, color) = get_border_property_values(); - properties.push(PropertyDeclaration::BorderTopWidth(width.clone())); + properties.push(PropertyDeclaration::BorderTopWidth(Box::new(width.clone()))); properties.push(PropertyDeclaration::BorderTopStyle(style.clone())); properties.push(PropertyDeclaration::BorderTopColor(color.clone())); - properties.push(PropertyDeclaration::BorderRightWidth(width.clone())); + properties.push(PropertyDeclaration::BorderRightWidth(Box::new(width.clone()))); properties.push(PropertyDeclaration::BorderRightStyle(style.clone())); properties.push(PropertyDeclaration::BorderRightColor(color.clone())); - properties.push(PropertyDeclaration::BorderBottomWidth(width.clone())); + properties.push(PropertyDeclaration::BorderBottomWidth(Box::new(width.clone()))); properties.push(PropertyDeclaration::BorderBottomStyle(style.clone())); properties.push(PropertyDeclaration::BorderBottomColor(color.clone())); - properties.push(PropertyDeclaration::BorderLeftWidth(width.clone())); + properties.push(PropertyDeclaration::BorderLeftWidth(Box::new(width.clone()))); properties.push(PropertyDeclaration::BorderLeftStyle(style.clone())); properties.push(PropertyDeclaration::BorderLeftColor(color.clone())); @@ -564,7 +564,7 @@ mod shorthand_serialization { let width = Either::Second(Auto); let count = Either::Second(Auto); - properties.push(PropertyDeclaration::ColumnWidth(width)); + properties.push(PropertyDeclaration::ColumnWidth(Box::new(width))); properties.push(PropertyDeclaration::ColumnCount(count)); let serialization = shorthand_properties_to_string(properties); diff --git a/tests/unit/style/properties/viewport.rs b/tests/unit/style/properties/viewport.rs index b217a413665..8b88d61f293 100644 --- a/tests/unit/style/properties/viewport.rs +++ b/tests/unit/style/properties/viewport.rs @@ -11,17 +11,17 @@ use style::values::specified::{Length, NoCalcLength, ViewportPercentageLength}; #[test] fn has_viewport_percentage_for_specified_value() { //TODO: test all specified value with a HasViewportPercentage impl - let pvw = PropertyDeclaration::BorderTopWidth( + let pvw = PropertyDeclaration::BorderTopWidth(Box::new( border_top_width::SpecifiedValue::from_length( Length::NoCalc(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.))) ) - ); + )); assert!(pvw.has_viewport_percentage()); - let pabs = PropertyDeclaration::BorderTopWidth( + let pabs = PropertyDeclaration::BorderTopWidth(Box::new( border_top_width::SpecifiedValue::from_length( Length::NoCalc(NoCalcLength::Absolute(Au(100))) ) - ); + )); assert!(!pabs.has_viewport_percentage()); }