Improve file pinning comments (#10387)

This commit is contained in:
konsti 2025-01-08 12:42:25 +01:00 committed by GitHub
parent fa305bd244
commit 68adadf806
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,11 +12,14 @@ use crate::candidate_selector::Candidate;
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub(crate) struct FilePins(FxHashMap<(PackageName, uv_pep440::Version), ResolvedDist>); pub(crate) struct FilePins(FxHashMap<(PackageName, uv_pep440::Version), ResolvedDist>);
// Inserts are common (every time we select a version) while reads are rare (converting the
// final resolution).
impl FilePins { impl FilePins {
/// Pin a candidate package. /// Pin a candidate package.
pub(crate) fn insert(&mut self, candidate: &Candidate, dist: &CompatibleDist) { pub(crate) fn insert(&mut self, candidate: &Candidate, dist: &CompatibleDist) {
self.0 self.0
.entry((candidate.name().clone(), candidate.version().clone())) .entry((candidate.name().clone(), candidate.version().clone()))
// Avoid the expensive clone when a version is selected again.
.or_insert_with(|| dist.for_installation().to_owned()); .or_insert_with(|| dist.for_installation().to_owned());
} }
@ -26,7 +29,6 @@ impl FilePins {
name: &PackageName, name: &PackageName,
version: &uv_pep440::Version, version: &uv_pep440::Version,
) -> Option<&ResolvedDist> { ) -> Option<&ResolvedDist> {
// Inserts are common while reads are rare, so the clone here is overall faster.
self.0.get(&(name.clone(), version.clone())) self.0.get(&(name.clone(), version.clone()))
} }
} }