Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Slightly improve performance of HTML serialization #431

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
perf: Slightly improve performance of HTML serialization
Signed-off-by: Dmitry Dygalo <[email protected]>
Stranger6667 committed Mar 11, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 533f7959f785f9af0a7ef1a668a3c0a1ecd9080e
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@

## [Unreleased]

### Performance

- Slightly improve performance of HTML serialization.

## [0.14.4] - 2024-12-27

### Changed
12 changes: 6 additions & 6 deletions css-inline/src/html/serializer.rs
Original file line number Diff line number Diff line change
@@ -171,12 +171,12 @@ impl<'a, W: Write> HtmlSerializer<'a, W> {
.expect("Invalid substring")
.as_bytes(),
)?;
match part {
"&" => self.writer.write_all(b"&amp;")?,
"\u{00A0}" => self.writer.write_all(b"&nbsp;")?,
"<" => self.writer.write_all(b"&lt;")?,
">" => self.writer.write_all(b"&gt;")?,
_ => unreachable!("Only the variants above are searched"),
match (part.as_bytes()[0] & 0b0000_1110) >> 1 {
1 => self.writer.write_all(b"&nbsp;")?,
3 => self.writer.write_all(b"&amp;")?,
6 => self.writer.write_all(b"&lt;")?,
7 => self.writer.write_all(b"&gt;")?,
_ => unreachable!(),
};
last_end = start.checked_add(part.len()).expect("Size overflow");
}