diff options
-rw-r--r-- | components/style/properties.mako.rs | 129 |
1 files changed, 77 insertions, 52 deletions
diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 6e9e4949644..5076f9e77e1 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -147,7 +147,7 @@ pub mod longhands { context: &computed::Context, seen: &mut PropertyBitField, cacheable: &mut bool, - error_reporter: Box<ParseErrorReporter + Send>) { + error_reporter: &mut Box<ParseErrorReporter + Send>) { let declared_value = match *declaration { PropertyDeclaration::${property.camel_case}(ref declared_value) => { declared_value @@ -176,7 +176,7 @@ pub mod longhands { .${property.ident} .clone() } - }, error_reporter.clone() + }, error_reporter ); Arc::make_mut(&mut style.${THIS_STYLE_STRUCT.ident}).${property.ident} = computed_value; @@ -537,7 +537,7 @@ pub mod longhands { context: &computed::Context, _seen: &mut PropertyBitField, _cacheable: &mut bool, - _error_reporter: Box<ParseErrorReporter + Send>) { + _error_reporter: &mut Box<ParseErrorReporter + Send>) { Arc::make_mut(&mut style.box_)._servo_display_for_hypothetical_box = longhands::_servo_display_for_hypothetical_box::derive_from_display( *computed_value, @@ -2239,7 +2239,7 @@ pub mod longhands { context: &computed::Context, _seen: &mut PropertyBitField, _cacheable: &mut bool, - _error_reporter: Box<ParseErrorReporter + Send>) { + _error_reporter: &mut Box<ParseErrorReporter + Send>) { Arc::make_mut(&mut style.inheritedtext)._servo_text_decorations_in_effect = longhands::_servo_text_decorations_in_effect::derive_from_text_decoration( *computed_value, @@ -5618,48 +5618,73 @@ mod property_bit_field { fn substitute_variables_${property.ident}<F, R>( value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>, custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>, - f: F, error_reporter: Box<ParseErrorReporter + Send>) + f: F, + error_reporter: &mut Box<ParseErrorReporter + Send>) -> R where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) -> R { if let DeclaredValue::WithVariables { ref css, first_token_type, ref base_url, from_shorthand } = *value { - f(& - ::custom_properties::substitute(css, first_token_type, custom_properties) - .and_then(|css| { - // As of this writing, only the base URL is used for property values: - let context = ParserContext::new( - ::stylesheets::Origin::Author, base_url, error_reporter); - Parser::new(&css).parse_entirely(|input| { - match from_shorthand { - None => { - longhands::${property.ident}::parse_specified(&context, input) - } - % for shorthand in SHORTHANDS: - % if property in shorthand.sub_properties: - Some(Shorthand::${shorthand.camel_case}) => { - shorthands::${shorthand.ident}::parse_value(&context, input) - .map(|result| match result.${property.ident} { - Some(value) => DeclaredValue::Value(value), - None => DeclaredValue::Initial, - }) - } - % endif - % endfor - _ => unreachable!() - } - }) - }) - .unwrap_or( - // Invalid at computed-value time. - DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"} - ) - ) + substitute_variables_${property.ident}_slow(css, + first_token_type, + base_url, + from_shorthand, + custom_properties, + f, + error_reporter) } else { f(value) } } + + #[inline(never)] + fn substitute_variables_${property.ident}_slow<F, R>( + css: &String, + first_token_type: TokenSerializationType, + base_url: &Url, + from_shorthand: Option<Shorthand>, + custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>, + f: F, + error_reporter: &mut Box<ParseErrorReporter + Send>) + -> R + where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) + -> R { + f(& + ::custom_properties::substitute(css, first_token_type, custom_properties) + .and_then(|css| { + // As of this writing, only the base URL is used for property values: + // + // FIXME(pcwalton): Cloning the error reporter is slow! But so are custom + // properties, so whatever... + let context = ParserContext::new( + ::stylesheets::Origin::Author, base_url, (*error_reporter).clone()); + Parser::new(&css).parse_entirely(|input| { + match from_shorthand { + None => { + longhands::${property.ident}::parse_specified(&context, input) + } + % for shorthand in SHORTHANDS: + % if property in shorthand.sub_properties: + Some(Shorthand::${shorthand.camel_case}) => { + shorthands::${shorthand.ident}::parse_value(&context, input) + .map(|result| match result.${property.ident} { + Some(value) => DeclaredValue::Value(value), + None => DeclaredValue::Initial, + }) + } + % endif + % endfor + _ => unreachable!() + } + }) + }) + .unwrap_or( + // Invalid at computed-value time. + DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"} + ) + ) + } % endif % endfor @@ -6395,7 +6420,7 @@ fn cascade_with_cached_declarations( cached_style: &ComputedValues, custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>, context: &computed::Context, - error_reporter: Box<ParseErrorReporter + Send>) + mut error_reporter: Box<ParseErrorReporter + Send>) -> ComputedValues { % for style_struct in STYLE_STRUCTS: % if style_struct.inherited: @@ -6439,7 +6464,7 @@ fn cascade_with_cached_declarations( .clone() } DeclaredValue::WithVariables { .. } => unreachable!() - }, error_reporter.clone() + }, &mut error_reporter ); Arc::make_mut(&mut style_${style_struct.ident}) .${property.ident} = computed_value; @@ -6495,7 +6520,7 @@ type CascadePropertyFn = extern "Rust" fn(declaration: &PropertyDeclaration, context: &computed::Context, seen: &mut PropertyBitField, cacheable: &mut bool, - error_reporter: Box<ParseErrorReporter + Send>); + error_reporter: &mut Box<ParseErrorReporter + Send>); // This is a thread-local rather than a lazy static to avoid atomic operations when cascading // properties. @@ -6541,7 +6566,7 @@ pub fn cascade(viewport_size: Size2D<Au>, shareable: bool, parent_style: Option< &ComputedValues >, cached_style: Option< &ComputedValues >, - error_reporter: Box<ParseErrorReporter + Send>) + mut error_reporter: Box<ParseErrorReporter + Send>) -> (ComputedValues, bool) { let initial_values = &*INITIAL_VALUES; let (is_root_element, inherited_style) = match parent_style { @@ -6605,7 +6630,7 @@ pub fn cascade(viewport_size: Size2D<Au>, inherited_style.$style_struct_getter().$property.clone() } DeclaredValue::WithVariables { .. } => unreachable!() - }, $error_reporter.clone() + }, &mut $error_reporter ) }; ); @@ -6644,7 +6669,7 @@ pub fn cascade(viewport_size: Size2D<Au>, DeclaredValue::Initial => longhands::font_size::get_initial_value(), DeclaredValue::Inherit => context.inherited_font_size, DeclaredValue::WithVariables { .. } => unreachable!(), - }, error_reporter.clone() + }, &mut error_reporter ); } PropertyDeclaration::Color(ref value) => { @@ -6656,35 +6681,35 @@ pub fn cascade(viewport_size: Size2D<Au>, DeclaredValue::Initial => longhands::color::get_initial_value(), DeclaredValue::Inherit => inherited_style.get_color().color.clone(), DeclaredValue::WithVariables { .. } => unreachable!(), - }, error_reporter.clone() + }, &mut error_reporter ); } PropertyDeclaration::Display(ref value) => { - context.display = get_specified!(get_box, display, value, error_reporter.clone()); + context.display = get_specified!(get_box, display, value, error_reporter); } PropertyDeclaration::Position(ref value) => { - context.positioned = match get_specified!(get_box, position, value, error_reporter.clone()) { + context.positioned = match get_specified!(get_box, position, value, error_reporter) { longhands::position::SpecifiedValue::absolute | longhands::position::SpecifiedValue::fixed => true, _ => false, } } PropertyDeclaration::OverflowX(ref value) => { - context.overflow_x = get_specified!(get_box, overflow_x, value, error_reporter.clone()); + context.overflow_x = get_specified!(get_box, overflow_x, value, error_reporter); } PropertyDeclaration::OverflowY(ref value) => { - context.overflow_y = get_specified!(get_box, overflow_y, value, error_reporter.clone()); + context.overflow_y = get_specified!(get_box, overflow_y, value, error_reporter); } PropertyDeclaration::Float(ref value) => { - context.floated = get_specified!(get_box, float, value, error_reporter.clone()) + context.floated = get_specified!(get_box, float, value, error_reporter) != longhands::float::SpecifiedValue::none; } PropertyDeclaration::TextDecoration(ref value) => { - context.text_decoration = get_specified!(get_text, text_decoration, value, error_reporter.clone()); + context.text_decoration = get_specified!(get_text, text_decoration, value, error_reporter); } PropertyDeclaration::OutlineStyle(ref value) => { context.outline_style_present = - match get_specified!(get_outline, outline_style, value, error_reporter.clone()) { + match get_specified!(get_outline, outline_style, value, error_reporter) { BorderStyle::none => false, _ => true, }; @@ -6692,7 +6717,7 @@ pub fn cascade(viewport_size: Size2D<Au>, % for side in ["top", "right", "bottom", "left"]: PropertyDeclaration::Border${side.capitalize()}Style(ref value) => { context.border_${side}_present = - match get_specified!(get_border, border_${side}_style, value, error_reporter.clone()) { + match get_specified!(get_border, border_${side}_style, value, error_reporter) { BorderStyle::none | BorderStyle::hidden => false, _ => true, }; @@ -6756,7 +6781,7 @@ pub fn cascade(viewport_size: Size2D<Au>, &context, &mut seen, &mut cacheable, - error_reporter.clone()); + &mut error_reporter); } } }); |