mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-19 20:18:43 +00:00
Optimize resolve_inner
: Avoid VersionReq::clone
(#656)
* Add new dep maybe-owned v0.3.4 to binstalk * Optimize `resolve_inner`: Avoid `VersionReq::clone` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
7656b887d9
commit
7b34178bcc
3 changed files with 10 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -177,6 +177,7 @@ dependencies = [
|
||||||
"home",
|
"home",
|
||||||
"itertools",
|
"itertools",
|
||||||
"jobslot",
|
"jobslot",
|
||||||
|
"maybe-owned",
|
||||||
"miette",
|
"miette",
|
||||||
"normalize-path",
|
"normalize-path",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
|
@ -23,6 +23,7 @@ futures-util = { version = "0.3.25", default-features = false, features = ["std"
|
||||||
home = "0.5.4"
|
home = "0.5.4"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
jobslot = { version = "0.2.8", features = ["tokio"] }
|
jobslot = { version = "0.2.8", features = ["tokio"] }
|
||||||
|
maybe-owned = "0.3.4"
|
||||||
miette = "5.5.0"
|
miette = "5.5.0"
|
||||||
normalize-path = { version = "0.2.0", path = "../normalize-path" }
|
normalize-path = { version = "0.2.0", path = "../normalize-path" }
|
||||||
once_cell = "1.17.0"
|
once_cell = "1.17.0"
|
||||||
|
|
|
@ -10,6 +10,7 @@ use cargo_toml::Manifest;
|
||||||
use compact_str::{CompactString, ToCompactString};
|
use compact_str::{CompactString, ToCompactString};
|
||||||
use crates_io_api::AsyncClient as CratesIoApiClient;
|
use crates_io_api::AsyncClient as CratesIoApiClient;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use maybe_owned::MaybeOwned;
|
||||||
use semver::{Version, VersionReq};
|
use semver::{Version, VersionReq};
|
||||||
use tokio::task::block_in_place;
|
use tokio::task::block_in_place;
|
||||||
use tracing::{debug, info, instrument, warn};
|
use tracing::{debug, info, instrument, warn};
|
||||||
|
@ -57,11 +58,11 @@ async fn resolve_inner(
|
||||||
) -> Result<Resolution, BinstallError> {
|
) -> Result<Resolution, BinstallError> {
|
||||||
info!("Resolving package: '{}'", crate_name);
|
info!("Resolving package: '{}'", crate_name);
|
||||||
|
|
||||||
let version_req: VersionReq = match (crate_name.version_req, &opts.version_req) {
|
let version_req = match (&crate_name.version_req, &opts.version_req) {
|
||||||
(Some(version), None) => version,
|
(Some(version), None) => MaybeOwned::Borrowed(version),
|
||||||
(None, Some(version)) => version.clone(),
|
(None, Some(version)) => MaybeOwned::Borrowed(version),
|
||||||
(Some(_), Some(_)) => Err(BinstallError::SuperfluousVersionOption)?,
|
(Some(_), Some(_)) => Err(BinstallError::SuperfluousVersionOption)?,
|
||||||
(None, None) => VersionReq::STAR,
|
(None, None) => MaybeOwned::Owned(VersionReq::STAR),
|
||||||
};
|
};
|
||||||
|
|
||||||
let version_req_str = version_req.to_compact_string();
|
let version_req_str = version_req.to_compact_string();
|
||||||
|
@ -69,7 +70,7 @@ async fn resolve_inner(
|
||||||
let Some(package_info) = PackageInfo::resolve(&opts,
|
let Some(package_info) = PackageInfo::resolve(&opts,
|
||||||
crate_name.name,
|
crate_name.name,
|
||||||
curr_version,
|
curr_version,
|
||||||
version_req,
|
&version_req,
|
||||||
opts.client.clone(),
|
opts.client.clone(),
|
||||||
&opts.crates_io_api_client).await?
|
&opts.crates_io_api_client).await?
|
||||||
else {
|
else {
|
||||||
|
@ -337,7 +338,7 @@ impl PackageInfo {
|
||||||
opts: &Options,
|
opts: &Options,
|
||||||
name: CompactString,
|
name: CompactString,
|
||||||
curr_version: Option<Version>,
|
curr_version: Option<Version>,
|
||||||
version_req: VersionReq,
|
version_req: &VersionReq,
|
||||||
client: Client,
|
client: Client,
|
||||||
crates_io_api_client: &CratesIoApiClient,
|
crates_io_api_client: &CratesIoApiClient,
|
||||||
) -> Result<Option<Self>, BinstallError> {
|
) -> Result<Option<Self>, BinstallError> {
|
||||||
|
@ -349,7 +350,7 @@ impl PackageInfo {
|
||||||
client,
|
client,
|
||||||
crates_io_api_client,
|
crates_io_api_client,
|
||||||
&name,
|
&name,
|
||||||
&version_req,
|
version_req,
|
||||||
))
|
))
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue