Skip to content

Commit f635292

Browse files
authored
perf: Remove unnecessary contains call (#512)
* perf: Remove unnecessary `contains` call Signed-off-by: Dmitry Dygalo <[email protected]> * chore: Update changelog Signed-off-by: Dmitry Dygalo <[email protected]> --------- Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent f487253 commit f635292

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- `keep_at_rules` option to keep all "at-rules" (ones starting with `@`) inside a "style" element. [#265](https://github.com/Stranger6667/css-inline/issues/265)
88

9+
### Performance
10+
11+
- Avoid unnecessary check for double quotes.
12+
913
## [0.16.0] - 2025-07-16
1014

1115
### Added

bindings/c/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- `keep_at_rules` option to keep all "at-rules" (ones starting with `@`) inside a "style" element [#265](https://github.com/Stranger6667/css-inline/issues/265)
88

9+
### Performance
10+
11+
- Avoid unnecessary check for double quotes.
12+
913
## [0.16.0] - 2025-07-16
1014

1115
### Changed

bindings/java/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- `keep_at_rules` option to keep all "at-rules" (ones starting with `@`) inside a "style" element [#265](https://github.com/Stranger6667/css-inline/issues/265)
88

9+
### Performance
10+
11+
- Avoid unnecessary check for double quotes.
12+
913
## [0.16.0] - 2025-07-16
1014

1115
### Changed

bindings/javascript/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- `keep_at_rules` option to keep all "at-rules" (ones starting with `@`) inside a "style" element [#265](https://github.com/Stranger6667/css-inline/issues/265)
88

9+
### Performance
10+
11+
- Avoid unnecessary check for double quotes.
12+
913
## [0.16.0] - 2025-07-16
1014

1115
### Changed

bindings/python/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- `keep_at_rules` option to keep all "at-rules" (ones starting with `@`) inside a "style" element [#265](https://github.com/Stranger6667/css-inline/issues/265)
88

9+
### Performance
10+
11+
- Avoid unnecessary check for double quotes.
12+
913
## [0.16.0] - 2025-07-16
1014

1115
### Changed

bindings/ruby/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- `keep_at_rules` option to keep all "at-rules" (ones starting with `@`) inside a "style" element [#265](https://github.com/Stranger6667/css-inline/issues/265)
88

9+
### Performance
10+
11+
- Avoid unnecessary check for double quotes.
12+
913
## [0.16.0] - 2025-07-16
1014

1115
### Changed

css-inline/src/html/serializer.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -428,28 +428,24 @@ fn write_declaration<Wr: Write>(
428428
#[inline]
429429
fn write_declaration_value<Wr: Write>(writer: &mut Wr, value: &str) -> Result<(), InlineError> {
430430
let value = value.trim();
431-
if value.as_bytes().contains(&b'"') {
432-
// Roughly based on `str::replace`
433-
let mut last_end = 0;
434-
for (start, part) in value.match_indices('"') {
435-
writer.write_all(
436-
value
437-
.get(last_end..start)
438-
.expect("Invalid substring")
439-
.as_bytes(),
440-
)?;
441-
writer.write_all(b"'")?;
442-
last_end = start.checked_add(part.len()).expect("Size overflow");
443-
}
431+
// Roughly based on `str::replace`
432+
let mut last_end = 0;
433+
for (start, part) in value.match_indices('"') {
444434
writer.write_all(
445435
value
446-
.get(last_end..value.len())
436+
.get(last_end..start)
447437
.expect("Invalid substring")
448438
.as_bytes(),
449439
)?;
450-
} else {
451-
writer.write_all(value.as_bytes())?;
440+
writer.write_all(b"'")?;
441+
last_end = start.checked_add(part.len()).expect("Size overflow");
452442
}
443+
writer.write_all(
444+
value
445+
.get(last_end..value.len())
446+
.expect("Invalid substring")
447+
.as_bytes(),
448+
)?;
453449
Ok(())
454450
}
455451

0 commit comments

Comments
 (0)