Skip to content

Commit 049ba12

Browse files
committed
Compute hashes in parallel
1 parent 5f82756 commit 049ba12

3 files changed

Lines changed: 60 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ cdb2 = "0.8"
1717
fiemap = "0.2"
1818
getrandom = "0.3"
1919
libc = "0.2"
20+
rayon = "1"
2021
serde = { version = "1", features = ["derive"] }
2122
xxhash-rust = { version = "0.8", features = ["xxh3"] }

src/index.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::utils;
2+
use rayon::prelude::*;
23
use std::collections::HashMap;
34
use std::fs;
45
use std::io::{ BufRead, BufReader, ErrorKind };
@@ -122,8 +123,9 @@ pub fn scandir(index: &mut Index, basedir: &Path, directory: &Path) {
122123
pub fn make_file_hashes(index: &mut Index,
123124
directory: &Path, indexfile: &IndexFile, args: &utils::Args) {
124125

125-
for subindex in index.values_mut() {
126-
for record in subindex {
126+
index.par_iter_mut()
127+
.flat_map(|(_, subindex)| subindex.par_iter_mut())
128+
.for_each(|record| {
127129
if ! args.paranoid {
128130
let path = record.path.to_path_buf().into_os_string().into_vec();
129131
let filerecord = indexfile.get(&path);
@@ -141,11 +143,10 @@ pub fn make_file_hashes(index: &mut Index,
141143

142144
let f = match fs::File::open(&path) {
143145
Ok(f) => f,
144-
Err(ref err) if err.kind() == ErrorKind::PermissionDenied
145-
=> continue,
146+
Err(ref err) if err.kind() == ErrorKind::PermissionDenied => return,
146147
Err(err) => {
147148
eprintln!("Warning: skipping {}: {err}", path.display());
148-
continue;
149+
return;
149150
}
150151
};
151152
let mut reader = BufReader::with_capacity(32768, f);
@@ -181,8 +182,7 @@ pub fn make_file_hashes(index: &mut Index,
181182
}
182183
}
183184
}
184-
}
185-
}
185+
});
186186
}
187187

188188
fn make_links(linkindex: &[IdxRecord], directory: &Path, args: &utils::Args) -> u64 {

0 commit comments

Comments
 (0)