diff --git a/src/render/context/mod.rs b/src/render/context/mod.rs index 50cb365a..7dafa470 100644 --- a/src/render/context/mod.rs +++ b/src/render/context/mod.rs @@ -94,8 +94,8 @@ pub struct Context { #[arg(short = 'S', long)] pub follow_links: bool, - /// Number of threads to use; defaults to number of logical cores available - #[arg(short, long, default_value_t = Context::default_threads())] + /// Number of threads to use + #[arg(short, long, default_value_t = 3)] pub threads: usize, /// Omit disk usage from output; disabled by default @@ -181,12 +181,6 @@ impl Context { Context::from_arg_matches(&user_args).map_err(|e| Error::ArgParse(e)) } - fn default_threads() -> usize { - available_parallelism() - .unwrap_or_else(|_| NonZeroUsize::new(1).unwrap()) - .get() - } - /// Returns reference to the path of the root directory to be traversed. pub fn dir(&self) -> &Path { self.dir diff --git a/src/render/tree/mod.rs b/src/render/tree/mod.rs index c3615e5d..13ce0014 100644 --- a/src/render/tree/mod.rs +++ b/src/render/tree/mod.rs @@ -72,17 +72,12 @@ impl Tree { /// parallel traversal; post-processing post-processing of all directory entries should /// be completely CPU-bound. fn traverse(ctx: &Context) -> TreeResult<(Arena, NodeId)> { - let walker = WalkParallel::try_from(ctx)?; let (tx, rx) = channel::unbounded::(); thread::scope(|s| { - let mut tree = Arena::new(); - let res = s.spawn(|| { - // Key represents path of parent directory and values represent children. + let mut tree = Arena::new(); let mut branches: HashMap> = HashMap::new(); - - // Set used to prevent double counting hard-links in the same file-tree hiearchy. let mut inodes = HashSet::new(); let mut root_id = None; @@ -135,6 +130,8 @@ impl Tree { let mut visitor_builder = BranchVisitorBuilder::new(ctx, Sender::clone(&tx)); + let walker = WalkParallel::try_from(ctx)?; + walker.visit(&mut visitor_builder); tx.send(TraversalState::Done).unwrap();