From 0b4877590fbb9b3ac2a7b4e08697627194c5e234 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 23 Feb 2017 17:48:51 +0100 Subject: [PATCH] Move deduplicate_property_declarations to PropertyDeclaration::deduplicate --- .../style/properties/declaration_block.rs | 35 +++++++++++++++++- .../style/properties/properties.mako.rs | 36 ------------------- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index bde41fc6d8e..949de6bd38e 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -274,6 +274,39 @@ impl PropertyDeclarationBlock { } } } + + /// Only keep the "winning" declaration for any given property, by importance then source order. + pub fn deduplicate(&mut self) { + let mut deduplicated = Vec::with_capacity(self.declarations.len()); + let mut seen_normal = PropertyDeclarationIdSet::new(); + let mut seen_important = PropertyDeclarationIdSet::new(); + + for (declaration, importance) in self.declarations.drain(..).rev() { + if importance.important() { + let id = declaration.id(); + if seen_important.contains(id) { + self.important_count -= 1; + continue + } + if seen_normal.contains(id) { + let previous_len = deduplicated.len(); + deduplicated.retain(|&(ref d, _)| PropertyDeclaration::id(d) != id); + debug_assert_eq!(deduplicated.len(), previous_len - 1); + } + seen_important.insert(id); + } else { + let id = declaration.id(); + if seen_normal.contains(id) || + seen_important.contains(id) { + continue + } + seen_normal.insert(id) + } + deduplicated.push((declaration, importance)) + } + deduplicated.reverse(); + self.declarations = deduplicated; + } } impl ToCss for PropertyDeclarationBlock { @@ -612,6 +645,6 @@ pub fn parse_property_declaration_list(context: &ParserContext, declarations: iter.parser.declarations, important_count: important_count, }; - super::deduplicate_property_declarations(&mut block); + block.deduplicate(); block } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 2dc8a452285..21839b9ec74 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -407,42 +407,6 @@ impl PropertyDeclarationIdSet { % endif % endfor -/// Given a property declaration block, only keep the "winning" declaration for -/// any given property, by importance then source order. -/// -/// The input and output are in source order -fn deduplicate_property_declarations(block: &mut PropertyDeclarationBlock) { - let mut deduplicated = Vec::with_capacity(block.declarations.len()); - let mut seen_normal = PropertyDeclarationIdSet::new(); - let mut seen_important = PropertyDeclarationIdSet::new(); - - for (declaration, importance) in block.declarations.drain(..).rev() { - if importance.important() { - let id = declaration.id(); - if seen_important.contains(id) { - block.important_count -= 1; - continue - } - if seen_normal.contains(id) { - let previous_len = deduplicated.len(); - deduplicated.retain(|&(ref d, _)| PropertyDeclaration::id(d) != id); - debug_assert_eq!(deduplicated.len(), previous_len - 1); - } - seen_important.insert(id); - } else { - let id = declaration.id(); - if seen_normal.contains(id) || - seen_important.contains(id) { - continue - } - seen_normal.insert(id) - } - deduplicated.push((declaration, importance)) - } - deduplicated.reverse(); - block.declarations = deduplicated; -} - /// An enum to represent a CSS Wide keyword. #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum CSSWideKeyword {