diff --git a/yazi-core/src/folder/sorter.rs b/yazi-core/src/folder/sorter.rs index 850e02490..779b22e29 100644 --- a/yazi-core/src/folder/sorter.rs +++ b/yazi-core/src/folder/sorter.rs @@ -80,11 +80,7 @@ impl FilesSorter { if self.reverse { ordering.reverse() } else { ordering } }); - let mut new = Vec::with_capacity(indices.len()); - for i in indices { - new.push(mem::take(&mut items[i])); - } - *items = new; + *items = indices.into_iter().map(|i| mem::take(&mut items[i])).collect(); } #[inline(always)] diff --git a/yazi-core/src/which/commands/show.rs b/yazi-core/src/which/commands/show.rs index 4794e6ecd..22994c6d7 100644 --- a/yazi-core/src/which/commands/show.rs +++ b/yazi-core/src/which/commands/show.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use yazi_config::{keymap::{Control, Key}, KEYMAP}; use yazi_shared::{event::Cmd, render, Layer}; -use crate::which::Which; +use crate::which::{Which, WhichSorter}; pub struct Opt { cands: Vec, @@ -52,7 +52,7 @@ impl Which { .map(|c| c.into()) .collect(); - self.sorter().sort(&mut self.cands); + WhichSorter::default().sort(&mut self.cands); self.visible = true; self.silent = false; render!(); diff --git a/yazi-core/src/which/sorter.rs b/yazi-core/src/which/sorter.rs index d9b196318..6fd64dc28 100644 --- a/yazi-core/src/which/sorter.rs +++ b/yazi-core/src/which/sorter.rs @@ -1,15 +1,25 @@ use std::{borrow::Cow, mem}; -use yazi_config::{keymap::ControlCow, which::SortBy}; +use yazi_config::{keymap::ControlCow, which::SortBy, WHICH}; use yazi_shared::natsort; -#[derive(Clone, Copy, Default, PartialEq)] +#[derive(Clone, Copy, PartialEq)] pub struct WhichSorter { pub by: SortBy, pub sensitive: bool, pub reverse: bool, } +impl Default for WhichSorter { + fn default() -> Self { + Self { + by: WHICH.sort_by, + sensitive: WHICH.sort_sensitive, + reverse: WHICH.sort_reverse, + } + } +} + impl WhichSorter { pub(super) fn sort(&self, items: &mut Vec) { if self.by == SortBy::None || items.is_empty() { @@ -32,10 +42,6 @@ impl WhichSorter { if self.reverse { ordering.reverse() } else { ordering } }); - let mut new = Vec::with_capacity(indices.len()); - for i in indices { - new.push(mem::take(&mut items[i])); - } - *items = new; + *items = indices.into_iter().map(|i| mem::take(&mut items[i])).collect(); } } diff --git a/yazi-core/src/which/which.rs b/yazi-core/src/which/which.rs index 3b34d6f59..d6227775c 100644 --- a/yazi-core/src/which/which.rs +++ b/yazi-core/src/which/which.rs @@ -1,19 +1,12 @@ -use yazi_config::{keymap::{ControlCow, Key}, which::SortBy}; +use yazi_config::keymap::{ControlCow, Key}; use yazi_shared::{emit, render, Layer}; -use super::WhichSorter; - -#[derive(Default, Debug)] +#[derive(Default)] pub struct Which { pub(super) layer: Layer, pub times: usize, pub cands: Vec, - // Sorting - sort_by: SortBy, - sort_sensitive: bool, - sort_reverse: bool, - // Visibility pub visible: bool, pub silent: bool, @@ -38,14 +31,6 @@ impl Which { true } - pub(super) fn sorter(&self) -> WhichSorter { - WhichSorter { - by: self.sort_by, - sensitive: self.sort_sensitive, - reverse: self.sort_reverse, - } - } - fn reset(&mut self) { self.times = 0; self.cands.clear();