Skip to content
Merged
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
26 changes: 8 additions & 18 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,25 +455,15 @@ impl<'a> Codegen<'a> {
self.needs_semicolon = false;
}

// We tried optimizing this to move the `index != 0` check out of the loop:
// ```
// let mut iter = items.iter();
// let Some(item) = iter.next() else { return };
// item.print(self, ctx);
// for item in iter {
// self.print_comma();
// self.print_soft_space();
// item.print(self, ctx);
// }
// ```
// But it turned out this was actually a bit slower.
// <https://github.com/oxc-project/oxc/pull/5221>
#[inline]
fn print_list<T: Gen>(&mut self, items: &[T], ctx: Context) {
for (index, item) in items.iter().enumerate() {
if index != 0 {
self.print_comma();
self.print_soft_space();
}
let Some((first, rest)) = items.split_first() else {
return;
};
first.print(self, ctx);
for item in rest {
self.print_comma();
self.print_soft_space();
item.print(self, ctx);
}
}
Expand Down
Loading