Reduce allocator churn when parsing property declaration blocks (fixes #15060)

This commit is contained in:
Manish Goregaokar 2017-01-17 18:56:42 -08:00
parent f010fb58fd
commit b5cb401aef
6 changed files with 81 additions and 49 deletions

View file

@ -406,6 +406,7 @@
use cssparser::Parser;
use parser::ParserContext;
use properties::{longhands, PropertyDeclaration, DeclaredValue, ShorthandId};
use properties::declaration_block::Importance;
use std::fmt;
use style_traits::ToCss;
use super::{SerializeFlags, ALL_INHERIT, ALL_INITIAL, ALL_UNSET};
@ -508,7 +509,7 @@
/// `declarations` vector.
pub fn parse(context: &ParserContext,
input: &mut Parser,
declarations: &mut Vec<PropertyDeclaration>)
declarations: &mut Vec<(PropertyDeclaration, Importance)>)
-> Result<(), ()> {
input.look_for_var_functions();
let start = input.position();
@ -519,12 +520,12 @@
let var = input.seen_var_functions();
if let Ok(value) = value {
% for sub_property in shorthand.sub_properties:
declarations.push(PropertyDeclaration::${sub_property.camel_case}(
declarations.push((PropertyDeclaration::${sub_property.camel_case}(
match value.${sub_property.ident} {
Some(value) => DeclaredValue::Value(value),
None => DeclaredValue::Initial,
}
));
), Importance::Normal));
% endfor
Ok(())
} else if var {
@ -532,14 +533,14 @@
let (first_token_type, css) = try!(
::custom_properties::parse_non_custom_with_var(input));
% for sub_property in shorthand.sub_properties:
declarations.push(PropertyDeclaration::${sub_property.camel_case}(
declarations.push((PropertyDeclaration::${sub_property.camel_case}(
DeclaredValue::WithVariables {
css: css.clone().into_owned(),
first_token_type: first_token_type,
base_url: context.base_url.clone(),
from_shorthand: Some(ShorthandId::${shorthand.camel_case}),
}
));
), Importance::Normal));
% endfor
Ok(())
} else {