Skip to content

Commit

Permalink
Even fewer temporary needless strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Sep 8, 2023
1 parent 2e2ca4c commit de1c6fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CargoResult<&str>> {
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();
Expand All @@ -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<CargoResult<impl Iterator<Item = &'a IndexSummary> + 'b>>
Expand All @@ -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
Expand Down Expand Up @@ -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<PackageId>,
Expand Down Expand Up @@ -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<PackageId>,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -647,7 +646,7 @@ impl<'cfg> RegistryIndex<'cfg> {
load: &mut dyn RegistryData,
) -> Poll<CargoResult<bool>> {
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))
Expand Down
10 changes: 6 additions & 4 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit de1c6fd

Please sign in to comment.