From c9c8412dc829b3e60a1f6577c85d4c1363a5dfab Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 4 Nov 2018 20:23:32 +0100 Subject: Code cleanup --- src/main.rs | 3 ++- src/walk.rs | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 966c3b3..83b1027 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,8 @@ fn main() { .and_then(|t| t.parse().ok()) .unwrap_or(3 * num_cpus::get()); - let paths = &[PathBuf::from(".")]; + let root = PathBuf::from("."); + let paths = &[root]; let walk = Walk::new(paths, num_threads); let size = walk.run(); print_result(size); diff --git a/src/walk.rs b/src/walk.rs index 9b660d7..a5daac6 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -8,9 +8,10 @@ use crossbeam_channel as channel; use rayon::prelude::*; -type UniqueID = (u64, u64); +#[derive(Eq,PartialEq,Hash)] +struct UniqueID(u64, u64); -type SizeEntry = (Option, u64); +struct SizeEntry(Option, u64); fn walk(tx: channel::Sender, entries: &[PathBuf]) { entries.into_par_iter().for_each_with(tx, |tx_ref, entry| { @@ -19,14 +20,14 @@ fn walk(tx: channel::Sender, entries: &[PathBuf]) { // a unique ID consisting of device and inode in order // not to count this entry twice. let unique_id = if metadata.is_file() && metadata.nlink() > 1 { - Some((metadata.dev(), metadata.ino())) + Some(UniqueID(metadata.dev(), metadata.ino())) } else { None }; let size = metadata.len(); - tx_ref.send((unique_id, size)).unwrap(); + tx_ref.send(SizeEntry(unique_id, size)).unwrap(); if metadata.is_dir() { let mut children = vec![]; @@ -63,7 +64,7 @@ impl<'a> Walk<'a> { let receiver_thread = thread::spawn(move || { let mut total = 0; let mut ids = HashSet::new(); - for (unique_id, size) in rx { + for SizeEntry(unique_id, size) in rx { if let Some(unique_id) = unique_id { // Only count this entry if the ID has not been seen if ids.insert(unique_id) { -- cgit v1.2.3