mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: avoid clone() reallocating memory
This commit is contained in:
parent
0f02b9e348
commit
1091b0c199
1 changed files with 10 additions and 12 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{collections::HashSet, str::FromStr};
|
use std::{collections::HashSet, str::FromStr};
|
||||||
|
|
||||||
use yazi_config::{keymap::{Control, ControlCow, Key}, KEYMAP};
|
use yazi_config::{keymap::{Control, Key}, KEYMAP};
|
||||||
use yazi_shared::{event::Cmd, render, Layer};
|
use yazi_shared::{event::Cmd, render, Layer};
|
||||||
|
|
||||||
use crate::which::{Which, WhichSorter};
|
use crate::which::{Which, WhichSorter};
|
||||||
|
|
@ -43,9 +43,17 @@ impl Which {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_with(&mut self, key: &Key, layer: Layer) {
|
pub fn show_with(&mut self, key: &Key, layer: Layer) {
|
||||||
|
let mut seen = HashSet::new();
|
||||||
|
|
||||||
self.layer = layer;
|
self.layer = layer;
|
||||||
self.times = 1;
|
self.times = 1;
|
||||||
self.cands = keymap_candidates(layer, key);
|
self.cands = KEYMAP
|
||||||
|
.get(layer)
|
||||||
|
.iter()
|
||||||
|
.filter(|c| c.on.len() > 1 && &c.on[0] == key)
|
||||||
|
.filter(|&c| seen.insert(&c.on))
|
||||||
|
.map(|c| c.into())
|
||||||
|
.collect();
|
||||||
|
|
||||||
WhichSorter::default().sort(&mut self.cands);
|
WhichSorter::default().sort(&mut self.cands);
|
||||||
self.visible = true;
|
self.visible = true;
|
||||||
|
|
@ -53,13 +61,3 @@ impl Which {
|
||||||
render!();
|
render!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keymap_candidates(layer: Layer, key: &Key) -> Vec<ControlCow> {
|
|
||||||
let mut seen = HashSet::new();
|
|
||||||
|
|
||||||
let mut matches =
|
|
||||||
KEYMAP.get(layer).iter().filter(|c| c.on.len() > 1 && &c.on[0] == key).collect::<Vec<_>>();
|
|
||||||
|
|
||||||
matches.retain(|c| seen.insert(c.on.clone()));
|
|
||||||
matches.into_iter().map(|c| c.into()).collect()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue