Refactor: Avoid repeated heap alloc of temp_dir

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-18 17:00:18 +10:00
parent d514219ee4
commit 8ca85382af
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -315,9 +315,11 @@ async fn entry() -> Result<()> {
.as_str(), .as_str(),
); );
let temp_dir_path = Arc::from(temp_dir.path());
let tasks: Vec<_> = resolutions let tasks: Vec<_> = resolutions
.into_iter() .into_iter()
.map(|resolution| install(resolution, &opts, temp_dir.path(), &target)) .map(|resolution| install(resolution, &opts, &temp_dir_path, &target))
.collect(); .collect();
for task in tasks { for task in tasks {
@ -502,7 +504,7 @@ fn collect_bin_files(
fn install( fn install(
resolution: Resolution, resolution: Resolution,
opts: &Arc<Options>, opts: &Arc<Options>,
temp_dir: &Path, temp_dir: &Arc<Path>,
target: &Arc<str>, target: &Arc<str>,
) -> tokio::task::JoinHandle<Result<()>> { ) -> tokio::task::JoinHandle<Result<()>> {
match resolution { match resolution {
@ -518,7 +520,7 @@ fn install(
opts.clone(), opts.clone(),
package, package,
crate_name, crate_name,
temp_dir.to_path_buf(), Arc::clone(temp_dir),
version, version,
bin_path, bin_path,
bin_files, bin_files,
@ -543,7 +545,7 @@ async fn install_from_package(
opts: Arc<Options>, opts: Arc<Options>,
package: Package<Meta>, package: Package<Meta>,
crate_name: CrateName, crate_name: CrateName,
temp_dir: PathBuf, temp_dir: Arc<Path>,
version: String, version: String,
bin_path: PathBuf, bin_path: PathBuf,
bin_files: Vec<bins::BinFile>, bin_files: Vec<bins::BinFile>,