mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-03 02:30:02 +00:00
Minor optimization (#544)
* Optimization: Rm `debug!` in `find_version` printing all version iterated obviously doesn't help much in debugging in the problem but rather just confusing. Also this makes it hard for the compiler to optimize the iterators. * Use let-else in `ManifestVisitor` * Optimize `BinFile::preview_{bin, link}` for zero-copy Return `impl Display` that lazily format instead of allocating a `String` * Optimize `infer_bin_dir_template`: Generate dir lazily * Optimize `find_version`: Lazily clone `version_req` only on err * Refactor `find_version`: Use `bool::then_some` * Add dep either v1.8.0 to binstalk * Optimize `GhCrateMeta::find`: Avoid cloning and `Vec` creation by using `Either` * Optimize `ops::install::install_from_package`: Make it a regular fn instead of async fn since it does not `.await` on any async fn. * Optimize `QuickInstall`: Rm field `target` since `Arc<Data>` already contains that field. * Optimize `Fetcher`s: Extract new struct `TargetData` so that `Data` can be shared by all fetchers, regardless of the target. * Optimize `QuickInstall`: Rm unused field `data` * Optimize `Resolution::print`: Replace branching with conditional move Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
696d8c2a82
commit
bdb4b2070d
11 changed files with 145 additions and 128 deletions
|
@ -19,7 +19,7 @@ use crate::{
|
|||
bins,
|
||||
drivers::fetch_crate_cratesio,
|
||||
errors::BinstallError,
|
||||
fetchers::{Data, Fetcher},
|
||||
fetchers::{Data, Fetcher, TargetData},
|
||||
helpers::{remote::Client, tasks::AutoAbortJoinHandle},
|
||||
manifests::cargo_toml_binstall::{Meta, PkgMeta, PkgOverride},
|
||||
};
|
||||
|
@ -58,17 +58,15 @@ impl Resolution {
|
|||
fetcher.source_name()
|
||||
);
|
||||
|
||||
if fetcher.is_third_party() {
|
||||
warn!(
|
||||
"The package will be downloaded from third-party source {}",
|
||||
fetcher.source_name()
|
||||
);
|
||||
} else {
|
||||
info!(
|
||||
"The package will be downloaded from {}",
|
||||
fetcher.source_name()
|
||||
);
|
||||
}
|
||||
warn!(
|
||||
"The package will be downloaded from {}{}",
|
||||
if fetcher.is_third_party() {
|
||||
"third-party source "
|
||||
} else {
|
||||
""
|
||||
},
|
||||
fetcher.source_name()
|
||||
);
|
||||
|
||||
info!("This will install the following binaries:");
|
||||
for file in bin_files {
|
||||
|
@ -138,6 +136,12 @@ async fn resolve_inner(
|
|||
let mut handles: Vec<(Arc<dyn Fetcher>, _)> =
|
||||
Vec::with_capacity(desired_targets.len() * resolvers.len());
|
||||
|
||||
let data = Arc::new(Data {
|
||||
name: package_info.name.clone(),
|
||||
version: package_info.version_str.clone(),
|
||||
repo: package_info.repo.clone(),
|
||||
});
|
||||
|
||||
handles.extend(
|
||||
desired_targets
|
||||
.iter()
|
||||
|
@ -150,17 +154,14 @@ async fn resolve_inner(
|
|||
|
||||
debug!("Found metadata: {target_meta:?}");
|
||||
|
||||
Arc::new(Data {
|
||||
name: package_info.name.clone(),
|
||||
Arc::new(TargetData {
|
||||
target: target.clone(),
|
||||
version: package_info.version_str.clone(),
|
||||
repo: package_info.repo.clone(),
|
||||
meta: target_meta,
|
||||
})
|
||||
})
|
||||
.cartesian_product(resolvers)
|
||||
.map(|(fetcher_data, f)| {
|
||||
let fetcher = f(&opts.client, &fetcher_data);
|
||||
.map(|(target_data, f)| {
|
||||
let fetcher = f(opts.client.clone(), data.clone(), target_data);
|
||||
(
|
||||
fetcher.clone(),
|
||||
AutoAbortJoinHandle::spawn(async move { fetcher.find().await }),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue