mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Use HashMap
This commit is contained in:
parent
b74eaecbfe
commit
6d06acd3a6
2 changed files with 9 additions and 13 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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<Mutex<(PathBuf, Option<bool>)>>,
|
||||
pending: Arc<Mutex<HashMap<PathBuf, Option<bool>>>>,
|
||||
}
|
||||
|
||||
impl Batcher {
|
||||
|
|
@ -13,26 +14,20 @@ impl Batcher {
|
|||
where
|
||||
T: Into<PathBuf>,
|
||||
{
|
||||
*self.pending.lock() = (target.into(), None);
|
||||
self.pending.lock().insert(target.into(), None);
|
||||
}
|
||||
|
||||
pub fn drain(&self, target: &Path) -> Option<bool> {
|
||||
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<T>(&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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue