From 4531842b404a6f399841c0bcbc32e600ac896fed Mon Sep 17 00:00:00 2001 From: arimu1 <19286898+arimu1@users.noreply.github.com> Date: Tue, 21 Jul 2026 06:55:46 +0700 Subject: [PATCH] fix(mgr): avoid Box allocation in MgrSnap::selected Iterate a &[UrlBuf] slice instead of boxing dyn Iterator. --- yazi-core/src/mgr/snap.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/yazi-core/src/mgr/snap.rs b/yazi-core/src/mgr/snap.rs index 5e4b659b..df93a2ae 100644 --- a/yazi-core/src/mgr/snap.rs +++ b/yazi-core/src/mgr/snap.rs @@ -1,5 +1,3 @@ -use std::iter; - use yazi_fs::Splatable; use yazi_shared::url::{AsUrl, Url, UrlBuf}; @@ -29,14 +27,13 @@ impl Splatable for MgrSnap { // Fall back to the hovered item when nothing is explicitly selected, the // same convention `Tab::selected_or_hovered_urls()` used before #4108. - let urls: Box> = - match tab.checked_sub(1).and_then(|tab| self.tabs.get(tab)) { - Some(s) if !s.selected.is_empty() => Box::new(s.selected.iter()), - Some(s) => Box::new(s.hovered.iter()), - None => Box::new(iter::empty()), - }; + let urls: &[UrlBuf] = match tab.checked_sub(1).and_then(|tab| self.tabs.get(tab)) { + Some(s) if !s.selected.is_empty() => &s.selected, + Some(s) => s.hovered.as_slice(), + None => &[], + }; - urls.skip(idx.unwrap_or(0)).take(if idx.is_some() { 1 } else { usize::MAX }).map(AsUrl::as_url) + urls.iter().skip(idx.unwrap_or(0)).take(if idx.is_some() { 1 } else { usize::MAX }).map(AsUrl::as_url) } fn hovered(&self, tab: usize) -> Option> {