mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-03 02:30:02 +00:00
Refactor and Optimizations (#459)
* Refactor: Avoid parsing `package.version()` twice in `ops::resolve` and `ops::install` * Optimize Resolution: Replace `Package<Meta>` with two `CompactStrings`: `name` and `version` * Use `CompactString` for `BinstallError::CratesIoApi::crate_name` * Use `CompactString` for `BinstallError::VersionParse::v` * Use `CompactString` for `BinstallError::VersionReq::req` * Use `CompactString` for `BinstallError::VersionUnavailable::crate_name` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
70b0f8ec97
commit
3421403e75
3 changed files with 38 additions and 42 deletions
|
@ -34,13 +34,14 @@ pub use version_ext::VersionReqExt;
|
|||
pub enum Resolution {
|
||||
Fetch {
|
||||
fetcher: Arc<dyn Fetcher>,
|
||||
package: Package<Meta>,
|
||||
new_version: Version,
|
||||
name: CompactString,
|
||||
version_req: CompactString,
|
||||
bin_files: Vec<bins::BinFile>,
|
||||
},
|
||||
InstallFromSource {
|
||||
package: Package<Meta>,
|
||||
name: CompactString,
|
||||
version: CompactString,
|
||||
},
|
||||
AlreadyUpToDate,
|
||||
}
|
||||
|
@ -154,13 +155,13 @@ async fn resolve_inner(
|
|||
.package
|
||||
.ok_or_else(|| BinstallError::CargoTomlMissingPackage(crate_name.name.clone()))?;
|
||||
|
||||
if let Some(curr_version) = curr_version {
|
||||
let new_version =
|
||||
Version::parse(package.version()).map_err(|err| BinstallError::VersionParse {
|
||||
v: package.version().to_string(),
|
||||
err,
|
||||
})?;
|
||||
let new_version =
|
||||
Version::parse(package.version()).map_err(|err| BinstallError::VersionParse {
|
||||
v: package.version().to_compact_string(),
|
||||
err,
|
||||
})?;
|
||||
|
||||
if let Some(curr_version) = curr_version {
|
||||
if new_version == curr_version {
|
||||
info!(
|
||||
"{} v{curr_version} is already installed, use --force to override",
|
||||
|
@ -246,7 +247,7 @@ async fn resolve_inner(
|
|||
if !bin_files.is_empty() {
|
||||
return Ok(Resolution::Fetch {
|
||||
fetcher,
|
||||
package,
|
||||
new_version,
|
||||
name: crate_name.name,
|
||||
version_req: version_req.to_compact_string(),
|
||||
bin_files,
|
||||
|
@ -279,7 +280,10 @@ async fn resolve_inner(
|
|||
}
|
||||
}
|
||||
|
||||
Ok(Resolution::InstallFromSource { package })
|
||||
Ok(Resolution::InstallFromSource {
|
||||
name: crate_name.name,
|
||||
version: package.version().to_compact_string(),
|
||||
})
|
||||
}
|
||||
|
||||
/// * `fetcher` - `fetcher.find()` must return `Ok(true)`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue