From 6d06acd3a6a50e235b4a0f8feb61225d3ad43f5c Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 21 Mar 2026 17:15:50 +0800 Subject: [PATCH] Use `HashMap` --- yazi-actor/src/mgr/bulk_rename.rs | 3 ++- yazi-core/src/mgr/batcher.rs | 19 +++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/yazi-actor/src/mgr/bulk_rename.rs b/yazi-actor/src/mgr/bulk_rename.rs index 6e106413..2681b9e6 100644 --- a/yazi-actor/src/mgr/bulk_rename.rs +++ b/yazi-actor/src/mgr/bulk_rename.rs @@ -46,7 +46,6 @@ impl Actor for BulkRename { tokio::spawn(async move { let tmp = YAZI.preview.tmpfile("bulk"); - batcher.prime(&tmp); Gate::default() .write(true) .create_new(true) @@ -62,6 +61,8 @@ impl Actor for BulkRename { Local::regular(&tmp).remove_file().await }); } + + batcher.prime(&tmp); TasksProxy::process_exec( cwd.into(), Splatter::new(&[UrlCow::default(), tmp.as_url().into()]).splat(&opener.run), diff --git a/yazi-core/src/mgr/batcher.rs b/yazi-core/src/mgr/batcher.rs index 1e1463ef..9b384c8b 100644 --- a/yazi-core/src/mgr/batcher.rs +++ b/yazi-core/src/mgr/batcher.rs @@ -1,11 +1,12 @@ use std::{path::{Path, PathBuf}, sync::Arc}; +use hashbrown::HashMap; use parking_lot::Mutex; use yazi_shared::url::AsUrl; #[derive(Clone, Default)] pub struct Batcher { - pending: Arc)>>, + pending: Arc>>>, } impl Batcher { @@ -13,26 +14,20 @@ impl Batcher { where T: Into, { - *self.pending.lock() = (target.into(), None); + self.pending.lock().insert(target.into(), None); } pub fn drain(&self, target: &Path) -> Option { - let mut pending = self.pending.lock(); - if pending.0 != target { - return None; - } - - pending.0 = PathBuf::default(); - pending.1.take() + self.pending.lock().remove(target).flatten() } pub fn decide(&self, target: T, decision: bool) where T: AsUrl, { - let mut pending = self.pending.lock(); - if target.as_url() == pending.0.as_url() { - pending.1 = Some(decision); + let Some(path) = target.as_url().as_local() else { return }; + if let Some(value) = self.pending.lock().get_mut(path) { + *value = Some(decision); } } }