diff --git a/crates/oxc_codegen/src/lib.rs b/crates/oxc_codegen/src/lib.rs index 127a3ed3a4a0c..ff6312999ab1f 100644 --- a/crates/oxc_codegen/src/lib.rs +++ b/crates/oxc_codegen/src/lib.rs @@ -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. - // + #[inline] fn print_list(&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); } }