Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve file pinning comments #10387

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/uv-resolver/src/pins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ use crate::candidate_selector::Candidate;
#[derive(Clone, Debug, Default)]
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 {
/// Pin a candidate package.
pub(crate) fn insert(&mut self, candidate: &Candidate, dist: &CompatibleDist) {
self.0
.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());
}

Expand All @@ -26,7 +29,6 @@ impl FilePins {
name: &PackageName,
version: &uv_pep440::Version,
) -> Option<&ResolvedDist> {
// Inserts are common while reads are rare, so the clone here is overall faster.
self.0.get(&(name.clone(), version.clone()))
}
}
Loading