summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-12-25 13:35:44 +0000
committerLars Wirzenius <liw@liw.fi>2020-12-25 13:35:44 +0000
commitbaec30fabed787722ff8e5359c65cbb5c10bceb5 (patch)
tree1a5749d500a49e6308ce43ecc56c990057ddec87
parentcf529f12223f571739ae33a4e2e9d31c27ba692d (diff)
parent085cd3c968de88a07251237232eb51c3d6ba26d8 (diff)
downloadsummain-rs-baec30fabed787722ff8e5359c65cbb5c10bceb5.tar.gz
Merge branch 'paral' into 'main'
refactor: use rayon to get some parallelism See merge request larswirzenius/summain!13
-rw-r--r--Cargo.toml1
-rw-r--r--src/bin/summain.rs14
-rw-r--r--src/lib.rs4
3 files changed, 11 insertions, 8 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 0f797c3..0729cc7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,6 +13,7 @@ edition = "2018"
[dependencies]
anyhow = "1"
digest = "0.9"
+rayon = "1.5"
serde = { version = "1", features = ["derive"] }
serde_yaml = "0.8"
sha2 = "0.9"
diff --git a/src/bin/summain.rs b/src/bin/summain.rs
index 0abe2f5..20ca738 100644
--- a/src/bin/summain.rs
+++ b/src/bin/summain.rs
@@ -1,4 +1,5 @@
use anyhow::Context;
+use rayon::prelude::*;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use summain::ManifestEntry;
@@ -6,8 +7,11 @@ use summain::ManifestEntry;
fn main() -> anyhow::Result<()> {
let mut opt = Opt::from_args();
opt.pathnames[..].sort();
- for pathname in opt.pathnames {
- report(&pathname).with_context(|| format!("{}", pathname.display()))?
+ let v: Vec<anyhow::Result<ManifestEntry>> =
+ opt.pathnames.par_iter().map(|p| manifest(&p)).collect();
+ for m in v {
+ let m = m?;
+ println!("{}", serde_yaml::to_string(&m)?);
}
Ok(())
}
@@ -18,8 +22,6 @@ struct Opt {
pathnames: Vec<PathBuf>,
}
-fn report(pathname: &Path) -> anyhow::Result<()> {
- let e = ManifestEntry::new(pathname)?;
- println!("{}", serde_yaml::to_string(&e)?);
- Ok(())
+fn manifest(path: &Path) -> anyhow::Result<ManifestEntry> {
+ ManifestEntry::new(path).with_context(|| format!("{}", path.display()))
}
diff --git a/src/lib.rs b/src/lib.rs
index 7db1115..3c90156 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,7 +42,7 @@ const BUF_SIZE: usize = 1024 * 1024;
/// An entry in a file manifest.
#[derive(Serialize, Debug)]
pub struct ManifestEntry {
- path: PathBuf,
+ path: String,
#[serde(with = "mode")]
mode: u32,
mtime: i64,
@@ -73,7 +73,7 @@ impl ManifestEntry {
None
};
Ok(Self {
- path: path.to_path_buf(),
+ path: path.to_string_lossy().into_owned(),
mode: m.st_mode(),
mtime: m.st_mtime(),
mtime_nsec: m.st_mtime_nsec(),