Deduplicate declarations when inserting each one, not at the end of parsing.

This will reduce the amount of re-allocations and copies.
It will be further optimized with a bit map.
This commit is contained in:
Simon Sapin 2017-03-07 19:38:25 +01:00
parent 4b4a873c3e
commit 460fd6eba8
3 changed files with 40 additions and 74 deletions

View file

@ -362,10 +362,10 @@ impl<'a> QualifiedRuleParser for KeyframeListParser<'a> {
context: self.context,
};
let mut iter = DeclarationListParser::new(input, parser);
let mut declarations = Vec::new();
let mut block = PropertyDeclarationBlock::new();
while let Some(declaration) = iter.next() {
match declaration {
Ok(parsed) => parsed.expand(|d| declarations.push((d, Importance::Normal))),
Ok(parsed) => parsed.expand(|d| block.push(d, Importance::Normal)),
Err(range) => {
let pos = range.start;
let message = format!("Unsupported keyframe property declaration: '{}'",
@ -377,10 +377,7 @@ impl<'a> QualifiedRuleParser for KeyframeListParser<'a> {
}
Ok(Arc::new(RwLock::new(Keyframe {
selector: prelude,
block: Arc::new(RwLock::new(PropertyDeclarationBlock {
declarations: declarations,
important_count: 0,
})),
block: Arc::new(RwLock::new(block)),
})))
}
}