mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-11 06:20:02 +00:00
Optimize main.rs
: Avoid frequent Box::clone
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
c66d8154eb
commit
bcb46cd736
1 changed files with 12 additions and 10 deletions
18
src/main.rs
18
src/main.rs
|
@ -230,10 +230,12 @@ async fn entry() -> Result<()> {
|
||||||
let desired_targets = get_desired_targets(&opts.targets);
|
let desired_targets = get_desired_targets(&opts.targets);
|
||||||
|
|
||||||
// Compute install directory
|
// Compute install directory
|
||||||
let install_path = get_install_path(opts.install_path.as_deref()).ok_or_else(|| {
|
let install_path: Arc<Path> = Arc::from(
|
||||||
|
get_install_path(opts.install_path.as_deref()).ok_or_else(|| {
|
||||||
error!("No viable install path found of specified, try `--install-path`");
|
error!("No viable install path found of specified, try `--install-path`");
|
||||||
miette!("No install path found or specified")
|
miette!("No install path found or specified")
|
||||||
})?;
|
})?,
|
||||||
|
);
|
||||||
debug!("Using install path: {}", install_path.display());
|
debug!("Using install path: {}", install_path.display());
|
||||||
|
|
||||||
// Create a temporary directory for downloads etc.
|
// Create a temporary directory for downloads etc.
|
||||||
|
@ -241,6 +243,8 @@ async fn entry() -> Result<()> {
|
||||||
.map_err(BinstallError::from)
|
.map_err(BinstallError::from)
|
||||||
.wrap_err("Creating a temporary directory failed.")?;
|
.wrap_err("Creating a temporary directory failed.")?;
|
||||||
|
|
||||||
|
let temp_dir_path: Arc<Path> = Arc::from(temp_dir.path());
|
||||||
|
|
||||||
let tasks: Vec<_> = crate_names
|
let tasks: Vec<_> = crate_names
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|crate_name| {
|
.map(|crate_name| {
|
||||||
|
@ -249,7 +253,7 @@ async fn entry() -> Result<()> {
|
||||||
crate_name,
|
crate_name,
|
||||||
desired_targets.clone(),
|
desired_targets.clone(),
|
||||||
cli_overrides.clone(),
|
cli_overrides.clone(),
|
||||||
temp_dir.path().to_path_buf(),
|
temp_dir_path.clone(),
|
||||||
install_path.clone(),
|
install_path.clone(),
|
||||||
client.clone(),
|
client.clone(),
|
||||||
))
|
))
|
||||||
|
@ -264,8 +268,6 @@ async fn entry() -> Result<()> {
|
||||||
.as_str(),
|
.as_str(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let temp_dir_path = Arc::from(temp_dir.path());
|
|
||||||
|
|
||||||
let tasks: Vec<_> = if !opts.dry_run && !opts.no_confirm {
|
let tasks: Vec<_> = if !opts.dry_run && !opts.no_confirm {
|
||||||
let mut resolutions = Vec::with_capacity(tasks.len());
|
let mut resolutions = Vec::with_capacity(tasks.len());
|
||||||
for task in tasks {
|
for task in tasks {
|
||||||
|
@ -383,8 +385,8 @@ async fn resolve(
|
||||||
crate_name: CrateName,
|
crate_name: CrateName,
|
||||||
desired_targets: DesiredTargets,
|
desired_targets: DesiredTargets,
|
||||||
cli_overrides: Arc<PkgOverride>,
|
cli_overrides: Arc<PkgOverride>,
|
||||||
temp_dir: PathBuf,
|
temp_dir: Arc<Path>,
|
||||||
install_path: PathBuf,
|
install_path: Arc<Path>,
|
||||||
client: Client,
|
client: Client,
|
||||||
) -> Result<Resolution> {
|
) -> Result<Resolution> {
|
||||||
info!("Installing package: '{}'", crate_name);
|
info!("Installing package: '{}'", crate_name);
|
||||||
|
@ -471,7 +473,7 @@ async fn resolve(
|
||||||
meta,
|
meta,
|
||||||
binaries,
|
binaries,
|
||||||
bin_path.clone(),
|
bin_path.clone(),
|
||||||
install_path,
|
install_path.to_path_buf(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Resolution::Fetch {
|
Ok(Resolution::Fetch {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue