diff --git a/src/main.rs b/src/main.rs index a464ef0f..e05201a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,9 +177,27 @@ fn main() { follow_links, progress_data: indicator.data.clone(), }; - - let custom_stack_size = config.get_custom_stack_size(&options); - let result = panic::catch_unwind(|| init_rayon(custom_stack_size)); + let stack_size = config.get_custom_stack_size(&options); + let result = panic::catch_unwind(|| { + match stack_size { + Some(n) => rayon::ThreadPoolBuilder::new().stack_size(n).build_global(), + None => { + let large_stack = usize::pow(1024, 3); + let mut s = System::new(); + s.refresh_memory(); + let available = s.available_memory(); + + if available > large_stack.try_into().unwrap() { + // Larger stack size to handle cases with lots of nested directories + rayon::ThreadPoolBuilder::new() + .stack_size(large_stack) + .build_global() + } else { + rayon::ThreadPoolBuilder::new().build_global() + } + } + } + }); if result.is_err() { eprintln!("Problem initializing rayon, try: export RAYON_NUM_THREADS=1") } @@ -227,24 +245,3 @@ fn main() { ) } } - -fn init_rayon(custom_stack_size: Option) -> Result<(), ThreadPoolBuildError> { - match custom_stack_size { - Some(n) => rayon::ThreadPoolBuilder::new().stack_size(n).build_global(), - None => { - let large_stack = usize::pow(1024, 3); - let mut s = System::new(); - s.refresh_memory(); - let available = s.available_memory(); - - if available > large_stack.try_into().unwrap() { - // Larger stack size to handle cases with lots of nested directories - rayon::ThreadPoolBuilder::new() - .stack_size(large_stack) - .build_global() - } else { - rayon::ThreadPoolBuilder::new().build_global() - } - } - } -}