Use HashMap

This commit is contained in:
sxyazi 2026-03-21 17:15:50 +08:00
parent b74eaecbfe
commit 6d06acd3a6
No known key found for this signature in database
2 changed files with 9 additions and 13 deletions

View file

@ -46,7 +46,6 @@ impl Actor for BulkRename {
tokio::spawn(async move { tokio::spawn(async move {
let tmp = YAZI.preview.tmpfile("bulk"); let tmp = YAZI.preview.tmpfile("bulk");
batcher.prime(&tmp);
Gate::default() Gate::default()
.write(true) .write(true)
.create_new(true) .create_new(true)
@ -62,6 +61,8 @@ impl Actor for BulkRename {
Local::regular(&tmp).remove_file().await Local::regular(&tmp).remove_file().await
}); });
} }
batcher.prime(&tmp);
TasksProxy::process_exec( TasksProxy::process_exec(
cwd.into(), cwd.into(),
Splatter::new(&[UrlCow::default(), tmp.as_url().into()]).splat(&opener.run), Splatter::new(&[UrlCow::default(), tmp.as_url().into()]).splat(&opener.run),

View file

@ -1,11 +1,12 @@
use std::{path::{Path, PathBuf}, sync::Arc}; use std::{path::{Path, PathBuf}, sync::Arc};
use hashbrown::HashMap;
use parking_lot::Mutex; use parking_lot::Mutex;
use yazi_shared::url::AsUrl; use yazi_shared::url::AsUrl;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct Batcher { pub struct Batcher {
pending: Arc<Mutex<(PathBuf, Option<bool>)>>, pending: Arc<Mutex<HashMap<PathBuf, Option<bool>>>>,
} }
impl Batcher { impl Batcher {
@ -13,26 +14,20 @@ impl Batcher {
where where
T: Into<PathBuf>, T: Into<PathBuf>,
{ {
*self.pending.lock() = (target.into(), None); self.pending.lock().insert(target.into(), None);
} }
pub fn drain(&self, target: &Path) -> Option<bool> { pub fn drain(&self, target: &Path) -> Option<bool> {
let mut pending = self.pending.lock(); self.pending.lock().remove(target).flatten()
if pending.0 != target {
return None;
}
pending.0 = PathBuf::default();
pending.1.take()
} }
pub fn decide<T>(&self, target: T, decision: bool) pub fn decide<T>(&self, target: T, decision: bool)
where where
T: AsUrl, T: AsUrl,
{ {
let mut pending = self.pending.lock(); let Some(path) = target.as_url().as_local() else { return };
if target.as_url() == pending.0.as_url() { if let Some(value) = self.pending.lock().get_mut(path) {
pending.1 = Some(decision); *value = Some(decision);
} }
} }
} }