mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-03 02:30:02 +00:00
Optimize bins::BinFile
(#422)
* Extract `infer_bin_dir_template` and call it once in `collect_bin_files` * Ensure `product.name.is_some()` is true * Avoid cloning `str` in `BinFile::from_product` * Optimize: Take reference in `bins::Data` * Optimize: Construct `CompactString` only when needed Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
3da5cb9d9c
commit
2cc12f9b69
3 changed files with 81 additions and 64 deletions
|
@ -1,4 +1,5 @@
|
|||
use std::{
|
||||
borrow::Cow,
|
||||
collections::BTreeSet,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
|
@ -168,7 +169,7 @@ async fn resolve_inner(
|
|||
}
|
||||
}
|
||||
|
||||
let (meta, binaries) = (
|
||||
let (meta, mut binaries) = (
|
||||
package
|
||||
.metadata
|
||||
.as_ref()
|
||||
|
@ -177,6 +178,8 @@ async fn resolve_inner(
|
|||
manifest.bin,
|
||||
);
|
||||
|
||||
binaries.retain(|product| product.name.is_some());
|
||||
|
||||
// Check binaries
|
||||
if binaries.is_empty() {
|
||||
return Err(BinstallError::UnspecifiedBinaries);
|
||||
|
@ -342,19 +345,26 @@ fn collect_bin_files(
|
|||
// List files to be installed
|
||||
// based on those found via Cargo.toml
|
||||
let bin_data = bins::Data {
|
||||
name: package.name.clone(),
|
||||
target: fetcher.target().to_string(),
|
||||
version: package.version.clone(),
|
||||
repo: package.repository.clone(),
|
||||
name: &package.name,
|
||||
target: fetcher.target(),
|
||||
version: &package.version,
|
||||
repo: package.repository.as_deref(),
|
||||
meta,
|
||||
bin_path,
|
||||
install_path,
|
||||
};
|
||||
|
||||
let bin_dir = bin_data
|
||||
.meta
|
||||
.bin_dir
|
||||
.as_deref()
|
||||
.map(Cow::Borrowed)
|
||||
.unwrap_or_else(|| bins::infer_bin_dir_template(&bin_data));
|
||||
|
||||
// Create bin_files
|
||||
let bin_files = binaries
|
||||
.iter()
|
||||
.map(|p| bins::BinFile::from_product(&bin_data, p))
|
||||
.map(|p| bins::BinFile::from_product(&bin_data, p, &bin_dir))
|
||||
.collect::<Result<Vec<_>, BinstallError>>()?;
|
||||
|
||||
let mut source_set = BTreeSet::new();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue