Skip to content

Commit

Permalink
Box larger specified values to avoid memmove impact
Browse files Browse the repository at this point in the history
  • Loading branch information
canova authored and SimonSapin committed Feb 9, 2017
1 parent abc40f6 commit 78afe2b
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 67 deletions.
10 changes: 5 additions & 5 deletions components/script/dom/element.rs
Expand Up @@ -407,7 +407,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
if let Some(color) = bgcolor {
hints.push(from_declaration(
PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
CSSColor { parsed: Color::RGBA(color), authored: None }))));
Box::new(CSSColor { parsed: Color::RGBA(color), authored: None })))));
}

let background = if let Some(this) = self.downcast::<HTMLBodyElement>() {
Expand Down Expand Up @@ -440,10 +440,10 @@ impl LayoutElementHelpers for LayoutJS<Element> {

if let Some(color) = color {
hints.push(from_declaration(
PropertyDeclaration::Color(DeclaredValue::Value(CSSRGBA {
PropertyDeclaration::Color(DeclaredValue::Value(Box::new(CSSRGBA {
parsed: color,
authored: None,
}))));
})))));
}

let font_family = if let Some(this) = self.downcast::<HTMLFontElement>() {
Expand Down Expand Up @@ -480,10 +480,10 @@ impl LayoutElementHelpers for LayoutJS<Element> {
let width_value = specified::Length::from_px(cellspacing as f32);
hints.push(from_declaration(
PropertyDeclaration::BorderSpacing(DeclaredValue::Value(
border_spacing::SpecifiedValue {
Box::new(border_spacing::SpecifiedValue {
horizontal: width_value.clone(),
vertical: width_value,
}))));
})))));
}


Expand Down
3 changes: 2 additions & 1 deletion components/style/properties/data.py
Expand Up @@ -96,7 +96,7 @@ def __init__(self, style_struct, name, spec=None, animatable=None, derived_from=
predefined_type=None, custom_cascade=False, experimental=False, internal=False,
need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False,
allowed_in_keyframe_block=True, complex_color=False, cast_type='u8',
has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None):
has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False):
self.name = name
if not spec:
raise TypeError("Spec should be specified for %s" % name)
Expand All @@ -119,6 +119,7 @@ def __init__(self, style_struct, name, spec=None, animatable=None, derived_from=
self.logical = arg_to_bool(logical)
self.alias = alias.split() if alias else []
self.extra_prefixes = extra_prefixes.split() if extra_prefixes else []
self.boxed = arg_to_bool(boxed)

# https://drafts.csswg.org/css-animations/#keyframes
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property
Expand Down
10 changes: 9 additions & 1 deletion components/style/properties/gecko.mako.rs
Expand Up @@ -168,8 +168,16 @@ impl ComputedValues {
PropertyDeclarationBlock {
declarations: vec![
(PropertyDeclaration::${prop.camel_case}(DeclaredValue::Value(
% if prop.boxed:
Box::new(
% endif
longhands::${prop.ident}::SpecifiedValue::from_computed_value(
&self.get_${prop.style_struct.ident.strip("_")}().clone_${prop.ident}()))),
&self.get_${prop.style_struct.ident.strip("_")}().clone_${prop.ident}())
% if prop.boxed:
)
% endif

)),
Importance::Normal)
],
important_count: 0
Expand Down
29 changes: 24 additions & 5 deletions components/style/properties/helpers.mako.rs
Expand Up @@ -9,8 +9,13 @@
${caller.body()}
% if not data.longhands_by_name[name].derived_from:
pub fn parse_specified(context: &ParserContext, input: &mut Parser)
-> Result<DeclaredValue<SpecifiedValue>, ()> {
parse(context, input).map(DeclaredValue::Value)
% if data.longhands_by_name[name].boxed:
-> Result<DeclaredValue<Box<SpecifiedValue>>, ()> {
parse(context, input).map(|result| DeclaredValue::Value(Box::new(result)))
% else:
-> Result<DeclaredValue<SpecifiedValue>, ()> {
parse(context, input).map(DeclaredValue::Value)
% endif
}
% endif
</%call>
Expand Down Expand Up @@ -298,7 +303,11 @@
}
% if not property.derived_from:
pub fn parse_declared(context: &ParserContext, input: &mut Parser)
-> Result<DeclaredValue<SpecifiedValue>, ()> {
% if property.boxed:
-> Result<DeclaredValue<Box<SpecifiedValue>>, ()> {
% else:
-> Result<DeclaredValue<SpecifiedValue>, ()> {
% endif
match input.try(|i| CSSWideKeyword::parse(context, i)) {
Ok(CSSWideKeyword::InheritKeyword) => Ok(DeclaredValue::Inherit),
Ok(CSSWideKeyword::InitialKeyword) => Ok(DeclaredValue::Initial),
Expand Down Expand Up @@ -429,7 +438,13 @@
/// correspond to a shorthand.
pub struct LonghandsToSerialize<'a> {
% for sub_property in shorthand.sub_properties:
pub ${sub_property.ident}: &'a DeclaredValue<longhands::${sub_property.ident}::SpecifiedValue>,
% if sub_property.boxed:
pub ${sub_property.ident}:
&'a DeclaredValue<Box<longhands::${sub_property.ident}::SpecifiedValue>>,
% else:
pub ${sub_property.ident}:
&'a DeclaredValue<longhands::${sub_property.ident}::SpecifiedValue>,
% endif
% endfor
}

Expand Down Expand Up @@ -529,7 +544,11 @@
% for sub_property in shorthand.sub_properties:
declarations.push((PropertyDeclaration::${sub_property.camel_case}(
match value.${sub_property.ident} {
Some(value) => DeclaredValue::Value(value),
% if sub_property.boxed:
Some(value) => DeclaredValue::Value(Box::new(value)),
% else:
Some(value) => DeclaredValue::Value(value),
% endif
None => DeclaredValue::Initial,
}
), Importance::Normal));
Expand Down
Expand Up @@ -278,7 +278,11 @@ impl AnimationValue {
AnimationValue::${prop.camel_case}(ref from) => {
PropertyDeclaration::${prop.camel_case}(
DeclaredValue::Value(
longhands::${prop.ident}::SpecifiedValue::from_computed_value(from)))
% if prop.boxed:
Box::new(longhands::${prop.ident}::SpecifiedValue::from_computed_value(from))))
% else:
longhands::${prop.ident}::SpecifiedValue::from_computed_value(from)))
% endif
}
% endif
% endfor
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/background.mako.rs
Expand Up @@ -9,7 +9,7 @@
${helpers.predefined_type("background-color", "CSSColor",
"::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */",
spec="https://drafts.csswg.org/css-backgrounds/#background-color",
animatable=True, complex_color=True)}
animatable=True, complex_color=True, boxed=True)}

<%helpers:vector_longhand name="background-image" animatable="False"
spec="https://drafts.csswg.org/css-backgrounds/#the-background-image"
Expand Down
4 changes: 2 additions & 2 deletions components/style/properties/longhand/border.mako.rs
Expand Up @@ -20,7 +20,7 @@
"::cssparser::Color::CurrentColor",
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-color"),
spec=maybe_logical_spec(side, "color"),
animatable=True, logical = side[1])}
animatable=True, logical = side[1], boxed=True)}
% endfor

% for side in ALL_SIDES:
Expand Down Expand Up @@ -83,7 +83,7 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-float-edge)",
animatable=False)}

<%helpers:longhand name="border-image-source" products="gecko" animatable="False"
<%helpers:longhand name="border-image-source" products="gecko" animatable="False" boxed="True"
spec="https://drafts.csswg.org/css-backgrounds/#border-image-source">
use std::fmt;
use style_traits::ToCss;
Expand Down
5 changes: 3 additions & 2 deletions components/style/properties/longhand/box.mako.rs
Expand Up @@ -1755,7 +1755,7 @@ ${helpers.single_keyword("transform-style",
extra_prefixes="moz webkit",
animatable=False)}

<%helpers:longhand name="transform-origin" animatable="True" extra_prefixes="moz webkit"
<%helpers:longhand name="transform-origin" animatable="True" extra_prefixes="moz webkit" boxed="True"
spec="https://drafts.csswg.org/css-transforms/#transform-origin-property">
use app_units::Au;
use std::fmt;
Expand Down Expand Up @@ -1896,7 +1896,8 @@ ${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)",
products="gecko",
animatable="False",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)",
disable_when_testing="True")}
disable_when_testing="True",
boxed=True)}

${helpers.single_keyword("-moz-orient",
"inline block horizontal vertical",
Expand Down
8 changes: 4 additions & 4 deletions components/style/properties/longhand/color.mako.rs
Expand Up @@ -6,7 +6,7 @@

<% data.new_style_struct("Color", inherited=True) %>

<%helpers:raw_longhand name="color" need_clone="True" animatable="True"
<%helpers:raw_longhand name="color" need_clone="True" animatable="True" boxed="True"
spec="https://drafts.csswg.org/css-color/#color">
use cssparser::Color as CSSParserColor;
use cssparser::RGBA;
Expand Down Expand Up @@ -39,15 +39,15 @@
RGBA { red: 0., green: 0., blue: 0., alpha: 1. } /* black */
}
pub fn parse_specified(context: &ParserContext, input: &mut Parser)
-> Result<DeclaredValue<SpecifiedValue>, ()> {
-> Result<DeclaredValue<Box<SpecifiedValue>>, ()> {
let value = try!(CSSColor::parse(context, input));
let rgba = match value.parsed {
CSSParserColor::RGBA(rgba) => rgba,
CSSParserColor::CurrentColor => return Ok(DeclaredValue::Inherit)
};
Ok(DeclaredValue::Value(CSSRGBA {
Ok(DeclaredValue::Value(Box::new(CSSRGBA {
parsed: rgba,
authored: value.authored,
}))
})))
}
</%helpers:raw_longhand>
2 changes: 1 addition & 1 deletion components/style/properties/longhand/column.mako.rs
Expand Up @@ -147,7 +147,7 @@ ${helpers.single_keyword("column-fill", "auto balance", extra_prefixes="moz",
${helpers.predefined_type("column-rule-color", "CSSColor",
"::cssparser::Color::CurrentColor",
products="gecko", animatable=True, extra_prefixes="moz",
complex_color=True, need_clone=True,
complex_color=True, need_clone=True, boxed=True,
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-color")}

// It's not implemented in servo or gecko yet.
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/effects.mako.rs
Expand Up @@ -77,7 +77,7 @@ ${helpers.predefined_type("opacity",
</%helpers:vector_longhand>

// FIXME: This prop should be animatable
<%helpers:longhand name="clip" products="servo" animatable="False"
<%helpers:longhand name="clip" products="servo" animatable="False" boxed="True"
spec="https://drafts.fxtf.org/css-masking/#clip-property">
use std::fmt;
use style_traits::ToCss;
Expand Down
Expand Up @@ -19,7 +19,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
animatable=False,
spec="https://drafts.csswg.org/css-tables/#propdef-caption-side")}

<%helpers:longhand name="border-spacing" animatable="False"
<%helpers:longhand name="border-spacing" animatable="False" boxed="True"
spec="https://drafts.csswg.org/css-tables/#propdef-border-spacing">
use app_units::Au;
use std::fmt;
Expand Down
7 changes: 4 additions & 3 deletions components/style/properties/longhand/inherited_text.mako.rs
Expand Up @@ -429,7 +429,7 @@ ${helpers.single_keyword("text-align-last",
<%helpers:longhand name="-servo-text-decorations-in-effect"
derived_from="display text-decoration"
need_clone="True" products="servo"
animatable="False"
animatable="False" boxed="True"
spec="Nonstandard (Internal property used by Servo)">
use cssparser::RGBA;
use std::fmt;
Expand Down Expand Up @@ -1027,6 +1027,7 @@ ${helpers.predefined_type("text-emphasis-color", "CSSColor",
"::cssparser::Color::CurrentColor",
products="gecko",animatable=True,
complex_color=True, need_clone=True,
boxed=True,
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-color")}

// CSS Compatibility
Expand All @@ -1035,14 +1036,14 @@ ${helpers.predefined_type(
"-webkit-text-fill-color", "CSSColor",
"CSSParserColor::CurrentColor",
products="gecko", animatable=True,
complex_color=True, need_clone=True,
complex_color=True, need_clone=True, boxed=True,
spec="https://compat.spec.whatwg.org/#the-webkit-text-fill-color")}

${helpers.predefined_type(
"-webkit-text-stroke-color", "CSSColor",
"CSSParserColor::CurrentColor",
products="gecko", animatable=True,
complex_color=True, need_clone=True,
complex_color=True, need_clone=True, boxed=True,
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")}

<%helpers:longhand products="gecko" name="-webkit-text-stroke-width" animatable="False"
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/list.mako.rs
Expand Up @@ -29,7 +29,7 @@ ${helpers.single_keyword("list-style-type", """
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}

${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)",
animatable="False",
animatable=False,
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image")}

<%helpers:longhand name="quotes" animatable="False"
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/outline.mako.rs
Expand Up @@ -11,7 +11,7 @@

// TODO(pcwalton): `invert`
${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor",
animatable=True, complex_color=True, need_clone=True,
animatable=True, complex_color=True, need_clone=True, boxed=True,
spec="https://drafts.csswg.org/css-ui/#propdef-outline-color")}

<%helpers:longhand name="outline-style" need_clone="True" animatable="False"
Expand Down
3 changes: 2 additions & 1 deletion components/style/properties/longhand/position.mako.rs
Expand Up @@ -218,5 +218,6 @@ ${helpers.single_keyword("object-fit", "fill contain cover none scale-down",
"Default::default()",
animatable=False,
spec="https://drafts.csswg.org/css-grid/#propdef-%s" % longhand,
products="gecko")}
products="gecko",
boxed=True)}
% endfor
5 changes: 4 additions & 1 deletion components/style/properties/longhand/svg.mako.rs
Expand Up @@ -25,6 +25,7 @@ ${helpers.predefined_type(
"CSSParserColor::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 })",
products="gecko",
animatable=False,
boxed=True,
spec="https://www.w3.org/TR/SVGTiny12/painting.html#StopColorProperty")}

${helpers.predefined_type("stop-opacity", "Opacity", "1.0",
Expand All @@ -39,6 +40,7 @@ ${helpers.predefined_type(
"CSSParserColor::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 })",
products="gecko",
animatable=False,
boxed=True,
spec="https://www.w3.org/TR/SVG/filters.html#FloodColorProperty")}

${helpers.predefined_type("flood-opacity", "Opacity",
Expand All @@ -50,6 +52,7 @@ ${helpers.predefined_type(
"CSSParserColor::RGBA(RGBA { red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0 })",
products="gecko",
animatable=False,
boxed=True,
spec="https://www.w3.org/TR/SVG/filters.html#LightingColorProperty")}

// CSS Masking Module Level 1
Expand All @@ -58,7 +61,7 @@ ${helpers.single_keyword("mask-type", "luminance alpha",
products="gecko", animatable=False,
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-type")}

<%helpers:longhand name="clip-path" animatable="False" products="gecko"
<%helpers:longhand name="clip-path" animatable="False" products="gecko" boxed="True"
spec="https://drafts.fxtf.org/css-masking/#propdef-clip-path">
use std::fmt;
use style_traits::ToCss;
Expand Down
3 changes: 2 additions & 1 deletion components/style/properties/longhand/text.mako.rs
Expand Up @@ -12,7 +12,7 @@
Method("has_overline", "bool"),
Method("has_line_through", "bool")]) %>

<%helpers:longhand name="text-overflow" animatable="False"
<%helpers:longhand name="text-overflow" animatable="False" boxed="True"
spec="https://drafts.csswg.org/css-ui/#propdef-text-overflow">
use std::fmt;
use style_traits::ToCss;
Expand Down Expand Up @@ -214,4 +214,5 @@ ${helpers.predefined_type(
complex_color=True,
products="gecko",
animatable=True,
boxed=True,
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-color")}

0 comments on commit 78afe2b

Please sign in to comment.