mirror of
https://github.com/bobwen-dev/hunter
synced 2025-04-12 00:55:41 +02:00
more prallel processing
This commit is contained in:
parent
049b1d1c74
commit
aa091b69c8
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -594,6 +594,7 @@ dependencies = [
|
||||
"gstreamer-player 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gstreamer-video 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"image 0.21.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lscolors 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -20,7 +20,7 @@ lazy_static = "1"
|
||||
alphanumeric-sort = "1.0.6"
|
||||
lscolors = { version = "0.5.0", features = [ "ansi_term" ] }
|
||||
tree_magic = "0.2.1"
|
||||
rayon = "1.0.3"
|
||||
rayon = "1.3"
|
||||
dirs-2 = "1.1.0"
|
||||
users = "0.8"
|
||||
chrono = "0.4"
|
||||
@ -42,6 +42,7 @@ strum = "0.15"
|
||||
strum_macros = "0.15"
|
||||
rust-ini = "0.13"
|
||||
derivative = "1.0.3"
|
||||
itertools = "0.8"
|
||||
|
||||
|
||||
image = { version = "0.21.1", optional = true }
|
||||
|
44
src/files.rs
44
src/files.rs
@ -378,14 +378,46 @@ impl Files {
|
||||
}
|
||||
|
||||
pub fn recalculate_len(&mut self) {
|
||||
self.len = self.iter_files().count();
|
||||
self.len = self.par_iter_files().count();
|
||||
}
|
||||
|
||||
pub fn get_file_mut(&mut self, index: usize) -> Option<&mut File> {
|
||||
self.iter_files_mut()
|
||||
.nth(index)
|
||||
self.par_iter_files_mut()
|
||||
.find_first(|(i, _)| *i == index)
|
||||
.map(|(_, f)| f)
|
||||
}
|
||||
|
||||
pub fn par_iter_files(&self) -> impl ParallelIterator<Item=&File> {
|
||||
let filter = self.filter.clone();
|
||||
let filter_selected = self.filter_selected;
|
||||
let show_hidden = self.show_hidden;
|
||||
|
||||
self.files
|
||||
.par_iter()
|
||||
.filter(move |f|
|
||||
f.kind == Kind::Placeholder ||
|
||||
!(filter.is_some() &&
|
||||
!f.name.contains(filter.as_ref().unwrap())) &&
|
||||
(!filter_selected || f.selected))
|
||||
.filter(move |f| !(!show_hidden && f.hidden))
|
||||
}
|
||||
|
||||
pub fn par_iter_files_mut(&mut self) -> impl ParallelIterator<Item=(usize,
|
||||
&mut File)> {
|
||||
let filter = self.filter.clone();
|
||||
let filter_selected = self.filter_selected;
|
||||
let show_hidden = self.show_hidden;
|
||||
|
||||
self.files
|
||||
.par_iter_mut()
|
||||
.enumerate()
|
||||
.filter(move |(_,f)|
|
||||
f.kind == Kind::Placeholder ||
|
||||
!(filter.is_some() &&
|
||||
!f.name.contains(filter.as_ref().unwrap())) &&
|
||||
(!filter_selected || f.selected))
|
||||
.filter(move |(_,f)| !(!show_hidden && f.hidden))
|
||||
}
|
||||
pub fn iter_files(&self) -> impl Iterator<Item=&File> {
|
||||
let filter = self.filter.clone();
|
||||
let filter_selected = self.filter_selected;
|
||||
@ -440,7 +472,7 @@ impl Files {
|
||||
match self.sort {
|
||||
SortBy::Name => self
|
||||
.files
|
||||
.sort_unstable_by(|a, b| {
|
||||
.par_sort_unstable_by(|a, b| {
|
||||
if dirs_first {
|
||||
match (a.is_dir(), b.is_dir()) {
|
||||
(true, false) => Less,
|
||||
@ -456,7 +488,7 @@ impl Files {
|
||||
self.meta_all_sync().log();
|
||||
}
|
||||
|
||||
self.files.sort_unstable_by(|a, b| {
|
||||
self.files.par_sort_unstable_by(|a, b| {
|
||||
if dirs_first {
|
||||
match (a.is_dir(), b.is_dir()) {
|
||||
(true, false) => return Less,
|
||||
@ -482,7 +514,7 @@ impl Files {
|
||||
self.meta_all_sync().log();
|
||||
}
|
||||
|
||||
self.files.sort_unstable_by(|a, b| {
|
||||
self.files.par_sort_unstable_by(|a, b| {
|
||||
if dirs_first {
|
||||
match (a.is_dir(), b.is_dir()) {
|
||||
(true, false) => return Less,
|
||||
|
Loading…
x
Reference in New Issue
Block a user