From 8f0c40f9a9488f9c688b1aae9206c1130edaa09a Mon Sep 17 00:00:00 2001 From: Dragyx <66752602+Dragyx@users.noreply.github.com> Date: Sun, 4 May 2025 18:51:56 +0200 Subject: [PATCH] src/main.rs: compute the closure size in the background --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 88867d0..ccd3982 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use std::{ collections::{HashMap, HashSet}, process::Command, string::{String, ToString}, + thread, }; #[derive(Parser, Debug)] @@ -40,6 +41,17 @@ fn main() { println!("<<< {}", args.path.to_string_lossy()); println!(">>> {}", args.path2.to_string_lossy()); + // handles to the threads collecting closure size information + let mut csize_pre_handle = None; + let mut csize_post_handle = None; + + // get closure size in the background to increase performance + if args.closure_size { + let (p1, p2) = (args.path.clone(), args.path2.clone()); + csize_pre_handle = Some(thread::spawn(move || get_closure_size(&p1))); + csize_post_handle = Some(thread::spawn(move || get_closure_size(&p2))); + } + let packages = get_packages(&args.path); let packages2 = get_packages(&args.path2); @@ -124,8 +136,8 @@ fn main() { } } if args.closure_size { - let closure_size_pre = get_closure_size(&args.path) as i64; - let closure_size_post = get_closure_size(&args.path2) as i64; + let closure_size_pre = csize_pre_handle.unwrap().join().unwrap() as i64; + let closure_size_post = csize_post_handle.unwrap().join().unwrap() as i64; println!("{}", "Closure Size:".underline().bold());