Skip to content

Commit 3e9c33a

Browse files
committed
perf: Avoid creating an unnecessary string cache entry
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent f635292 commit 3e9c33a

File tree

8 files changed

+19
-4
lines changed

8 files changed

+19
-4
lines changed

CHANGELOG.md

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

1111
- Avoid unnecessary check for double quotes.
12+
- Avoid creating an unnecessary string cache entry.
1213

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

bindings/c/CHANGELOG.md

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

1111
- Avoid unnecessary check for double quotes.
12+
- Avoid creating an unnecessary string cache entry.
1213

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

bindings/java/CHANGELOG.md

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

1111
- Avoid unnecessary check for double quotes.
12+
- Avoid creating an unnecessary string cache entry.
1213

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

bindings/javascript/CHANGELOG.md

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

1111
- Avoid unnecessary check for double quotes.
12+
- Avoid creating an unnecessary string cache entry.
1213

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

bindings/python/CHANGELOG.md

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

1111
- Avoid unnecessary check for double quotes.
12+
- Avoid creating an unnecessary string cache entry.
1213

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

bindings/ruby/CHANGELOG.md

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

1111
- Avoid unnecessary check for double quotes.
12+
- Avoid creating an unnecessary string cache entry.
1213

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

css-inline/src/html/attributes.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ impl Attributes {
172172
let needle = QualName::new(None, ns!(), local);
173173
self.find(&needle)
174174
}
175+
176+
pub(crate) fn get_css_inline(&self) -> Option<&str> {
177+
self.attributes.iter().find_map(|probe| {
178+
if probe.name.local == *CSS_INLINE_ATTRIBUTE {
179+
Some(&*probe.value)
180+
} else {
181+
None
182+
}
183+
})
184+
}
175185
}
176186

177187
#[cfg(test)]

css-inline/src/html/serializer.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ impl<'a> Sink<'a> {
7676
#[inline]
7777
fn should_skip_element(&self, element: &ElementData) -> bool {
7878
if element.name.local == local_name!("style") {
79-
!self.keep_style_tags
80-
&& element.attributes.get("data-css-inline".into()) != Some("keep")
79+
!self.keep_style_tags && element.attributes.get_css_inline() != Some("keep")
8180
} else if element.name.local == local_name!("link")
8281
&& element.attributes.get(local_name!("rel")) == Some("stylesheet")
8382
{
@@ -135,7 +134,7 @@ impl<'a> Sink<'a> {
135134
}
136135
NodeData::Document => self.serialize_children(serializer),
137136
NodeData::Doctype { name } => serializer.write_doctype(name),
138-
NodeData::Text { text: content } => serializer.write_text(content),
137+
NodeData::Text { text } => serializer.write_text(text),
139138
NodeData::Comment { text } => serializer.write_comment(text),
140139
NodeData::ProcessingInstruction { target, data } => {
141140
serializer.write_processing_instruction(target, data)
@@ -299,7 +298,7 @@ impl<'a, W: Write> HtmlSerializer<'a, W> {
299298
}
300299
self.writer.write_all(b"\"")?;
301300
}
302-
if let Some(styles) = &styles {
301+
if let Some(styles) = styles {
303302
self.writer.write_all(b" style=\"")?;
304303
for (property, (_, value)) in styles {
305304
write_declaration(&mut self.writer, property, value)?;

0 commit comments

Comments
 (0)