From 605a29068ed04ff529828ca9d77b670007eb39a5 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Mon, 22 Dec 2025 13:50:02 +0000 Subject: [PATCH] perf(semantic): use swap_remove instead of into_iter().next() in into_root (#17183) --- crates/oxc_semantic/src/unresolved_stack.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/oxc_semantic/src/unresolved_stack.rs b/crates/oxc_semantic/src/unresolved_stack.rs index d6c160cf1698a..34bd6fb579abd 100644 --- a/crates/oxc_semantic/src/unresolved_stack.rs +++ b/crates/oxc_semantic/src/unresolved_stack.rs @@ -105,10 +105,12 @@ impl<'a> UnresolvedReferencesStack<'a> { } #[inline] - pub(crate) fn into_root(self) -> TempUnresolvedReferences<'a> { + pub(crate) fn into_root(mut self) -> TempUnresolvedReferences<'a> { // SAFETY: Stack starts with a non-zero size and never shrinks. - // This assertion removes bounds check in `.next()`. + // This assertion removes bounds check in `swap_remove`. unsafe { assert_unchecked!(!self.stack.is_empty()) }; - self.stack.into_iter().next().unwrap() + // Use `swap_remove(0)` instead of `into_iter().next().unwrap()` to avoid + // creating an iterator just to get the first element. + self.stack.swap_remove(0) } }