From 8ca85382afe349d7ebdb4e4e7370bfa454c0542f Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Mon, 18 Jul 2022 17:00:18 +1000 Subject: [PATCH] Refactor: Avoid repeated heap alloc of `temp_dir` Signed-off-by: Jiahao XU --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index de2f5d39..f813467c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,9 +315,11 @@ async fn entry() -> Result<()> { .as_str(), ); + let temp_dir_path = Arc::from(temp_dir.path()); + let tasks: Vec<_> = resolutions .into_iter() - .map(|resolution| install(resolution, &opts, temp_dir.path(), &target)) + .map(|resolution| install(resolution, &opts, &temp_dir_path, &target)) .collect(); for task in tasks { @@ -502,7 +504,7 @@ fn collect_bin_files( fn install( resolution: Resolution, opts: &Arc, - temp_dir: &Path, + temp_dir: &Arc, target: &Arc, ) -> tokio::task::JoinHandle> { match resolution { @@ -518,7 +520,7 @@ fn install( opts.clone(), package, crate_name, - temp_dir.to_path_buf(), + Arc::clone(temp_dir), version, bin_path, bin_files, @@ -543,7 +545,7 @@ async fn install_from_package( opts: Arc, package: Package, crate_name: CrateName, - temp_dir: PathBuf, + temp_dir: Arc, version: String, bin_path: PathBuf, bin_files: Vec,