From de1c6fddca0f16034276f8a7e86b5cbdc72fc26e Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Fri, 8 Sep 2023 20:51:05 +0000 Subject: [PATCH] Even fewer temporary needless strings --- src/cargo/sources/registry/index.rs | 13 ++++++------- src/cargo/sources/registry/mod.rs | 10 ++++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/cargo/sources/registry/index.rs b/src/cargo/sources/registry/index.rs index f4a7c17a8a6f..bd6d73898b70 100644 --- a/src/cargo/sources/registry/index.rs +++ b/src/cargo/sources/registry/index.rs @@ -408,7 +408,7 @@ impl<'cfg> RegistryIndex<'cfg> { /// the index file, aka [`IndexSummary`]. pub fn hash(&mut self, pkg: PackageId, load: &mut dyn RegistryData) -> Poll> { let req = OptVersionReq::exact(pkg.version()); - let summary = self.summaries(&pkg.name(), &req, load)?; + let summary = self.summaries(pkg.name(), &req, load)?; let summary = ready!(summary) .filter(|s| s.package_id().version() == pkg.version()) .next(); @@ -432,7 +432,7 @@ impl<'cfg> RegistryIndex<'cfg> { /// though since this method is called quite a lot on null builds in Cargo. fn summaries<'a, 'b>( &'a mut self, - name: &str, + name: InternedString, req: &'b OptVersionReq, load: &mut dyn RegistryData, ) -> Poll + 'b>> @@ -444,7 +444,6 @@ impl<'cfg> RegistryIndex<'cfg> { let source_id = self.source_id; // First up parse what summaries we have available. - let name = InternedString::new(name); let summaries = ready!(self.load_summaries(name, load)?); // Iterate over our summaries, extract all relevant ones which match our @@ -539,7 +538,7 @@ impl<'cfg> RegistryIndex<'cfg> { /// This is primarily used by [`Source::query`](super::Source). pub fn query_inner( &mut self, - name: &str, + name: InternedString, req: &OptVersionReq, load: &mut dyn RegistryData, yanked_whitelist: &HashSet, @@ -572,7 +571,7 @@ impl<'cfg> RegistryIndex<'cfg> { /// The `online` controls whether Cargo can access the network when needed. fn query_inner_with_online( &mut self, - name: &str, + name: InternedString, req: &OptVersionReq, load: &mut dyn RegistryData, yanked_whitelist: &HashSet, @@ -604,7 +603,7 @@ impl<'cfg> RegistryIndex<'cfg> { .map(|s| s.clone()); // Handle `cargo update --precise` here. - let precise = source_id.precise_registry_version(name); + let precise = source_id.precise_registry_version(name.as_str()); let summaries = summaries.filter(|s| match &precise { Some((current, requested)) => { if req.matches(current) { @@ -647,7 +646,7 @@ impl<'cfg> RegistryIndex<'cfg> { load: &mut dyn RegistryData, ) -> Poll> { let req = OptVersionReq::exact(pkg.version()); - let found = ready!(self.summaries(&pkg.name(), &req, load))? + let found = ready!(self.summaries(pkg.name(), &req, load))? .filter(|s| s.package_id().version() == pkg.version()) .any(|summary| matches!(summary, IndexSummary::Yanked(_))); Poll::Ready(Ok(found)) diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index d8fc47ba9754..fb8f79817883 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -207,6 +207,7 @@ use crate::sources::source::QueryKind; use crate::sources::source::Source; use crate::sources::PathSource; use crate::util::hex; +use crate::util::interning::InternedString; use crate::util::network::PollExt; use crate::util::{restricted_names, CargoResult, Config, Filesystem, LimitErrorReader}; @@ -717,7 +718,7 @@ impl<'cfg> Source for RegistrySource<'cfg> { debug!("attempting query without update"); let mut called = false; ready!(self.index.query_inner( - &dep.package_name(), + dep.package_name(), dep.version_req(), &mut *self.ops, &self.yanked_whitelist, @@ -738,7 +739,7 @@ impl<'cfg> Source for RegistrySource<'cfg> { } else { let mut called = false; ready!(self.index.query_inner( - &dep.package_name(), + dep.package_name(), dep.version_req(), &mut *self.ops, &self.yanked_whitelist, @@ -768,13 +769,14 @@ impl<'cfg> Source for RegistrySource<'cfg> { dep.package_name().replace('-', "_"), dep.package_name().replace('_', "-"), ] { - if name_permutation.as_str() == dep.package_name().as_str() { + let name_permutation = InternedString::new(&name_permutation); + if name_permutation == dep.package_name() { continue; } any_pending |= self .index .query_inner( - &name_permutation, + name_permutation, dep.version_req(), &mut *self.ops, &self.yanked_whitelist,