diff --git a/crates/oxc_codegen/src/lib.rs b/crates/oxc_codegen/src/lib.rs index ff47797a5..5f254ce2a 100644 --- a/crates/oxc_codegen/src/lib.rs +++ b/crates/oxc_codegen/src/lib.rs @@ -411,13 +411,25 @@ 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.gen(self, ctx); + // for item in iter { + // self.print_comma(); + // self.print_soft_space(); + // item.gen(self, ctx); + // } + // ``` + // But it turned out this was actually a bit slower. + // fn print_list(&mut self, items: &[T], ctx: Context) { - let mut iter = items.iter(); - let Some(item) = iter.next() else { return }; - item.gen(self, ctx); - for item in iter { - self.print_comma(); - self.print_soft_space(); + for (index, item) in items.iter().enumerate() { + if index != 0 { + self.print_comma(); + self.print_soft_space(); + } item.gen(self, ctx); } }