Skip to content

Commit 5fbf952

Browse files
committed
perf: exit early if block comment ends at end of quasi
1 parent 0e149a5 commit 5fbf952

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

crates/oxc_transformer/src/plugins/styled_components.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -902,24 +902,31 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a
902902

903903
// Find end of comment
904904
let start_index = if is_block_comment {
905-
bytes.windows(2).position(|q| q == b"*/").map(|mut pos| {
906-
pos += 2;
907-
// Add a space when this is a own line block comment
908-
if pos < bytes.len()
909-
&& !bytes[pos].is_ascii_whitespace()
910-
&& output.last().is_some_and(|&last| last != b' ')
911-
{
912-
output.push(b' ');
913-
}
914-
pos
915-
})
916-
} else {
917-
bytes.iter().position(|&b| matches!(b, b'\n' | b'\r'))
918-
};
905+
let Some(mut pos) = bytes.windows(2).position(|q| q == b"*/") else {
906+
// Comment contains whole of this quasi
907+
continue;
908+
};
919909

920-
let Some(start_index) = start_index else {
921-
// Comment contains whole of this quasi. Remove it.
922-
return false;
910+
pos += 2;
911+
if pos == bytes.len() {
912+
// Comment ends at end of quasi
913+
continue;
914+
}
915+
916+
// Add a space when this is a own line block comment
917+
if !bytes[pos].is_ascii_whitespace()
918+
&& output.last().is_some_and(|&last| last != b' ')
919+
{
920+
output.push(b' ');
921+
}
922+
923+
pos
924+
} else {
925+
let Some(pos) = bytes.iter().position(|&b| matches!(b, b'\n' | b'\r')) else {
926+
// Comment contains whole of this quasi
927+
continue;
928+
};
929+
pos
923930
};
924931

925932
// Trim off to end of comment

0 commit comments

Comments
 (0)