From 0f592b67bba0b2f71fabe6af3cc368bcf4fffd25 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 15 Jan 2024 16:18:12 -0500 Subject: [PATCH] Remove clone from `RegistryWheelIndex` (#937) Doesn't need to own the package names. --- crates/puffin-dev/src/install_many.rs | 6 +++--- .../src/index/registry_wheel_index.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/puffin-dev/src/install_many.rs b/crates/puffin-dev/src/install_many.rs index 0d3aaa3f4..b7904c6f3 100644 --- a/crates/puffin-dev/src/install_many.rs +++ b/crates/puffin-dev/src/install_many.rs @@ -142,16 +142,16 @@ async fn install_chunk( .collect::>(); let mut registry_index = RegistryWheelIndex::new(build_dispatch.cache(), tags, index_locations); - let (cached, uncached): (Vec<_>, Vec<_>) = dists.into_iter().partition_map(|dist| { + let (cached, uncached): (Vec<_>, Vec<_>) = dists.iter().partition_map(|dist| { // We always want the wheel for the latest version not whatever matching is in cache. let VersionOrUrl::Version(version) = dist.version_or_url() else { - unreachable!(); + unreachable!("Only registry distributions are supported"); }; if let Some(cached) = registry_index.get_version(dist.name(), version) { Either::Left(CachedDist::Registry(cached.clone())) } else { - Either::Right(dist) + Either::Right(dist.clone()) } }); info!("Cached: {}, Uncached {}", cached.len(), uncached.len()); diff --git a/crates/puffin-distribution/src/index/registry_wheel_index.rs b/crates/puffin-distribution/src/index/registry_wheel_index.rs index 154002acf..06d318f7a 100644 --- a/crates/puffin-distribution/src/index/registry_wheel_index.rs +++ b/crates/puffin-distribution/src/index/registry_wheel_index.rs @@ -19,7 +19,7 @@ pub struct RegistryWheelIndex<'a> { cache: &'a Cache, tags: &'a Tags, index_locations: &'a IndexLocations, - index: FxHashMap>, + index: FxHashMap<&'a PackageName, BTreeMap>, } impl<'a> RegistryWheelIndex<'a> { @@ -38,7 +38,7 @@ impl<'a> RegistryWheelIndex<'a> { /// If the package is not yet indexed, this will index the package by reading from the cache. pub fn get( &mut self, - name: &PackageName, + name: &'a PackageName, ) -> impl Iterator { self.get_impl(name).iter().rev() } @@ -48,15 +48,15 @@ impl<'a> RegistryWheelIndex<'a> { /// If the package is not yet indexed, this will index the package by reading from the cache. pub fn get_version( &mut self, - name: &PackageName, + name: &'a PackageName, version: &Version, ) -> Option<&CachedRegistryDist> { self.get_impl(name).get(version) } /// Get an entry in the index. - fn get_impl(&mut self, name: &PackageName) -> &BTreeMap { - let versions = match self.index.entry(name.clone()) { + fn get_impl(&mut self, name: &'a PackageName) -> &BTreeMap { + let versions = match self.index.entry(name) { Entry::Occupied(entry) => entry.into_mut(), Entry::Vacant(entry) => entry.insert(Self::index( name,