mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Move deduplicate_property_declarations to PropertyDeclaration::deduplicate
This commit is contained in:
parent
066c5a01b2
commit
0b4877590f
2 changed files with 34 additions and 37 deletions
|
@ -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 {
|
impl ToCss for PropertyDeclarationBlock {
|
||||||
|
@ -612,6 +645,6 @@ pub fn parse_property_declaration_list(context: &ParserContext,
|
||||||
declarations: iter.parser.declarations,
|
declarations: iter.parser.declarations,
|
||||||
important_count: important_count,
|
important_count: important_count,
|
||||||
};
|
};
|
||||||
super::deduplicate_property_declarations(&mut block);
|
block.deduplicate();
|
||||||
block
|
block
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,42 +407,6 @@ impl PropertyDeclarationIdSet {
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% 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.
|
/// An enum to represent a CSS Wide keyword.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
pub enum CSSWideKeyword {
|
pub enum CSSWideKeyword {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue