diff --git a/crates/uv-resolver/src/pins.rs b/crates/uv-resolver/src/pins.rs index 73623f92c..b7e96f9b8 100644 --- a/crates/uv-resolver/src/pins.rs +++ b/crates/uv-resolver/src/pins.rs @@ -10,15 +10,14 @@ use crate::candidate_selector::Candidate; /// For example, given `Flask==3.0.0`, the [`FilePins`] would contain a mapping from `Flask` to /// `3.0.0` to the specific wheel or source distribution archive that was pinned for that version. #[derive(Clone, Debug, Default)] -pub(crate) struct FilePins(FxHashMap>); +pub(crate) struct FilePins(FxHashMap<(PackageName, uv_pep440::Version), ResolvedDist>); impl FilePins { /// Pin a candidate package. pub(crate) fn insert(&mut self, candidate: &Candidate, dist: &CompatibleDist) { - self.0.entry(candidate.name().clone()).or_default().insert( - candidate.version().clone(), - dist.for_installation().to_owned(), - ); + self.0 + .entry((candidate.name().clone(), candidate.version().clone())) + .or_insert_with(|| dist.for_installation().to_owned()); } /// Return the pinned file for the given package name and version, if it exists. @@ -27,6 +26,7 @@ impl FilePins { name: &PackageName, version: &uv_pep440::Version, ) -> Option<&ResolvedDist> { - self.0.get(name)?.get(version) + // Inserts are common while reads are rare, so the clone here is overall faster. + self.0.get(&(name.clone(), version.clone())) } }