Skip to content

Commit 3b48196

Browse files
committed
perf: Avoid hashtable rebuilding on small hashmaps
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent 8b9815f commit 3b48196

File tree

7 files changed

+11
-1
lines changed

7 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
1313
- Use a more precise estimate for the size of the number of applied styles.
14+
- Avoid hashtable rebuilding on small hashmaps.
1415

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

bindings/c/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
1313
- Use a more precise estimate for the size of the number of applied styles.
14+
- Avoid hashtable rebuilding on small hashmaps.
1415

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

bindings/java/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
1313
- Use a more precise estimate for the size of the number of applied styles.
14+
- Avoid hashtable rebuilding on small hashmaps.
1415

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

bindings/javascript/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
1313
- Use a more precise estimate for the size of the number of applied styles.
14+
- Avoid hashtable rebuilding on small hashmaps.
1415

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

bindings/python/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
1313
- Use a more precise estimate for the size of the number of applied styles.
14+
- Avoid hashtable rebuilding on small hashmaps.
1415

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

bindings/ruby/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Avoid unnecessary check for double quotes.
1212
- Avoid creating an unnecessary string cache entry.
1313
- Use a more precise estimate for the size of the number of applied styles.
14+
- Avoid hashtable rebuilding on small hashmaps.
1415

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

css-inline/src/html/serializer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ impl<'a, W: Write> HtmlSerializer<'a, W> {
248248

249249
let mut styles = if let Some(node_id) = style_node_id {
250250
self.styles.swap_remove(&node_id).map(|mut styles| {
251-
styles.sort_unstable_by(|_, (a, _), _, (b, _)| a.cmp(b));
251+
// Even though, there is a fast path for sorting of <2 elements, `indexmap` still
252+
// rebuilds the hashtable unnecessarily
253+
if styles.len() > 1 {
254+
styles.sort_unstable_by(|_, (a, _), _, (b, _)| a.cmp(b));
255+
}
252256
styles
253257
})
254258
} else {

0 commit comments

Comments
 (0)