diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-12-25 13:35:44 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-12-25 13:35:44 +0000 |
commit | baec30fabed787722ff8e5359c65cbb5c10bceb5 (patch) | |
tree | 1a5749d500a49e6308ce43ecc56c990057ddec87 | |
parent | cf529f12223f571739ae33a4e2e9d31c27ba692d (diff) | |
parent | 085cd3c968de88a07251237232eb51c3d6ba26d8 (diff) | |
download | summain-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.toml | 1 | ||||
-rw-r--r-- | src/bin/summain.rs | 14 | ||||
-rw-r--r-- | src/lib.rs | 4 |
3 files changed, 11 insertions, 8 deletions
@@ -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())) } @@ -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(), |