Skip to content

Commit 76d54db

Browse files
committed
perf: Allocate hashmap of the more appropriate size upfront during style merging
1 parent e06eb1c commit 76d54db

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ fn merge_styles(existing_style: &str, new_styles: &[Declaration]) -> Result<Stri
174174
let declarations =
175175
cssparser::DeclarationListParser::new(&mut parser, parse::CSSDeclarationListParser);
176176
// Merge existing with the new ones
177-
let mut styles: HashMap<String, String> = HashMap::new();
177+
// We know that at least one rule already exists, so we add 1
178+
let mut styles: HashMap<String, String> =
179+
HashMap::with_capacity(new_styles.len().saturating_add(1));
178180
for declaration in declarations.into_iter() {
179181
let (property, value) = declaration?;
180182
styles.insert(property, value);

0 commit comments

Comments
 (0)