mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix(mgr): avoid Box allocation in MgrSnap::selected
Iterate a &[UrlBuf] slice instead of boxing dyn Iterator.
This commit is contained in:
parent
2e60b1741b
commit
4531842b40
1 changed files with 6 additions and 9 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
use std::iter;
|
|
||||||
|
|
||||||
use yazi_fs::Splatable;
|
use yazi_fs::Splatable;
|
||||||
use yazi_shared::url::{AsUrl, Url, UrlBuf};
|
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
|
// Fall back to the hovered item when nothing is explicitly selected, the
|
||||||
// same convention `Tab::selected_or_hovered_urls()` used before #4108.
|
// same convention `Tab::selected_or_hovered_urls()` used before #4108.
|
||||||
let urls: Box<dyn Iterator<Item = &UrlBuf>> =
|
let urls: &[UrlBuf] = match tab.checked_sub(1).and_then(|tab| self.tabs.get(tab)) {
|
||||||
match tab.checked_sub(1).and_then(|tab| self.tabs.get(tab)) {
|
Some(s) if !s.selected.is_empty() => &s.selected,
|
||||||
Some(s) if !s.selected.is_empty() => Box::new(s.selected.iter()),
|
Some(s) => s.hovered.as_slice(),
|
||||||
Some(s) => Box::new(s.hovered.iter()),
|
None => &[],
|
||||||
None => Box::new(iter::empty()),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
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<Url<'_>> {
|
fn hovered(&self, tab: usize) -> Option<Url<'_>> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue