Skip to content

Commit 8b9815f

Browse files
committed
perf: Use a more precise estimate for the size of the number of applied styles
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent 3e9c33a commit 8b9815f

File tree

7 files changed

+10
-1
lines changed

7 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
13+
- Use a more precise estimate for the size of the number of applied styles.
1314

1415
## [0.16.0] - 2025-07-16
1516

bindings/c/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
13+
- Use a more precise estimate for the size of the number of applied styles.
1314

1415
## [0.16.0] - 2025-07-16
1516

bindings/java/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
13+
- Use a more precise estimate for the size of the number of applied styles.
1314

1415
## [0.16.0] - 2025-07-16
1516

bindings/javascript/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
13+
- Use a more precise estimate for the size of the number of applied styles.
1314

1415
## [0.16.0] - 2025-07-16
1516

bindings/python/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
13+
- Use a more precise estimate for the size of the number of applied styles.
1314

1415
## [0.16.0] - 2025-07-16
1516

bindings/ruby/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
13+
- Use a more precise estimate for the size of the number of applied styles.
1314

1415
## [0.16.0] - 2025-07-16
1516

css-inline/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ impl<'a> CSSInliner<'a> {
426426
if let Some(css) = css {
427427
raw_styles.push_str(css);
428428
}
429-
let mut styles = IndexMap::with_capacity_and_hasher(128, BuildNoHashHasher::default());
430429
let mut parse_input = cssparser::ParserInput::new(&raw_styles);
431430
let mut parser = cssparser::Parser::new(&mut parse_input);
432431
// Allocating some memory for all the parsed declarations
@@ -469,6 +468,10 @@ impl<'a> CSSInliner<'a> {
469468
} else {
470469
None
471470
};
471+
let mut styles = IndexMap::with_capacity_and_hasher(
472+
document.elements.len().max(16),
473+
BuildNoHashHasher::default(),
474+
);
472475
// This cache is unused but required in the `selectors` API
473476
let mut caches = SelectorCaches::default();
474477
for (selectors, (start, end)) in &rule_list {

0 commit comments

Comments
 (0)