diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index cbaaaa91edf..f09a2dc6b34 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -788,7 +788,7 @@ impl Element { // than that. let existing_declarations = Arc::make_mut(existing_declarations); - while let Some(mut incoming_declaration) = declarations.pop() { + for mut incoming_declaration in declarations { let mut replaced = false; for existing_declaration in &mut *existing_declarations { if existing_declaration.name() == incoming_declaration.name() { @@ -799,8 +799,7 @@ impl Element { } if !replaced { - // inserting instead of pushing since the declarations are in reverse order - existing_declarations.insert(0, incoming_declaration); + existing_declarations.push(incoming_declaration); } } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index d1ad214810b..d971b1c6eab 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -14,7 +14,7 @@ use std::ascii::AsciiExt; use std::boxed::Box as StdBox; use std::collections::HashSet; use std::fmt::{self, Write}; -use std::iter::{Iterator, Chain, Zip, Rev, Repeat, repeat}; +use std::iter::{Iterator, Chain, Zip, Repeat, repeat}; use std::slice; use std::sync::Arc; @@ -296,12 +296,11 @@ pub struct PropertyDeclarationBlock { impl PropertyDeclarationBlock { /// Provides an iterator of all declarations, with indication of !important value pub fn declarations(&self) -> Chain< - Zip>, Repeat>, - Zip>, Repeat> + Zip, Repeat>, + Zip, Repeat> > { - // Declarations are stored in reverse order. - let normal = self.normal.iter().rev().zip(repeat(Importance::Normal)); - let important = self.important.iter().rev().zip(repeat(Importance::Important)); + let normal = self.normal.iter().zip(repeat(Importance::Normal)); + let important = self.important.iter().zip(repeat(Importance::Important)); normal.chain(important) } } @@ -589,7 +588,7 @@ pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Pars /// Only keep the last declaration for any given property. -/// The input is in source order, output in reverse source order. +/// The input and output are in source order fn deduplicate_property_declarations(declarations: Vec) -> Vec { let mut deduplicated = vec![]; @@ -618,6 +617,7 @@ fn deduplicate_property_declarations(declarations: Vec) } deduplicated.push(declaration) } + deduplicated.reverse(); deduplicated } @@ -1683,8 +1683,7 @@ fn cascade_with_cached_declarations( // Declaration blocks are stored in increasing precedence order, // we want them in decreasing order here. for sub_list in applicable_declarations.iter().rev() { - // Declarations are already stored in reverse order. - for declaration in sub_list.declarations.iter() { + for declaration in sub_list.declarations.iter().rev() { match *declaration { % for style_struct in data.active_style_structs(): % for property in style_struct.longhands: @@ -1815,8 +1814,7 @@ pub fn cascade(viewport_size: Size2D, let mut custom_properties = None; let mut seen_custom = HashSet::new(); for sub_list in applicable_declarations.iter().rev() { - // Declarations are already stored in reverse order. - for declaration in sub_list.declarations.iter() { + for declaration in sub_list.declarations.iter().rev() { match *declaration { PropertyDeclaration::Custom(ref name, ref value) => { ::custom_properties::cascade( @@ -1874,8 +1872,7 @@ pub fn cascade(viewport_size: Size2D, ComputedValues::do_cascade_property(|cascade_property| { % for category_to_cascade_now in ["early", "other"]: for sub_list in applicable_declarations.iter().rev() { - // Declarations are already stored in reverse order. - for declaration in sub_list.declarations.iter() { + for declaration in sub_list.declarations.iter().rev() { if let PropertyDeclaration::Custom(..) = *declaration { continue } diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 7ff65edd959..98ffa07f722 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -39,8 +39,6 @@ fn property_declaration_block_should_serialize_correctly() { let height = DeclaredValue::Value(LengthOrPercentageOrAuto::Length(Length::from_px(20f32))); important.push(PropertyDeclaration::Height(height)); - normal.reverse(); - important.reverse(); let block = PropertyDeclarationBlock { normal: Arc::new(normal), important: Arc::new(important) diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index 2eb5f9f3260..72273165b35 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -39,6 +39,16 @@ fn test_parse_stylesheet() { let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent, Box::new(CSSErrorReporterTest), ParserContextExtraData::default()); + macro_rules! assert_eq { + ($left: expr, $right: expr) => { + let left = $left; + let right = $right; + if left != right { + panic!("{:#?} != {:#?}", left, right) + } + } + } + assert_eq!(stylesheet, Stylesheet { origin: Origin::UserAgent, media: None, @@ -157,13 +167,6 @@ fn test_parse_stylesheet() { ], declarations: PropertyDeclarationBlock { normal: Arc::new(vec![ - PropertyDeclaration::BackgroundClip(DeclaredValue::Initial), - PropertyDeclaration::BackgroundOrigin(DeclaredValue::Initial), - PropertyDeclaration::BackgroundSize(DeclaredValue::Initial), - PropertyDeclaration::BackgroundImage(DeclaredValue::Initial), - PropertyDeclaration::BackgroundAttachment(DeclaredValue::Initial), - PropertyDeclaration::BackgroundRepeat(DeclaredValue::Initial), - PropertyDeclaration::BackgroundPosition(DeclaredValue::Initial), PropertyDeclaration::BackgroundColor(DeclaredValue::Value( longhands::background_color::SpecifiedValue { authored: Some("blue".to_owned()), @@ -172,6 +175,13 @@ fn test_parse_stylesheet() { }), } )), + PropertyDeclaration::BackgroundPosition(DeclaredValue::Initial), + PropertyDeclaration::BackgroundRepeat(DeclaredValue::Initial), + PropertyDeclaration::BackgroundAttachment(DeclaredValue::Initial), + PropertyDeclaration::BackgroundImage(DeclaredValue::Initial), + PropertyDeclaration::BackgroundSize(DeclaredValue::Initial), + PropertyDeclaration::BackgroundOrigin(DeclaredValue::Initial), + PropertyDeclaration::BackgroundClip(DeclaredValue::Initial), ]), important: Arc::new(vec![]), },