Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Dec 12, 2024
1 parent 3ee2052 commit 3ff3d9e
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions crates/uv-resolver/src/pubgrub/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl PubGrubPriorities {
match self.0.entry(name.clone()) {
std::collections::hash_map::Entry::Occupied(mut entry) => {
// Preserve the original index.
let index = Self::get_index(next, &mut entry);
let index = Self::get_index(&entry).unwrap_or(next);

// Compute the priority.
let priority = if urls.get(name).is_some() {
Expand Down Expand Up @@ -80,14 +80,14 @@ impl PubGrubPriorities {
}
}

fn get_index(next: usize, entry: &mut OccupiedEntry<PackageName, PubGrubPriority>) -> usize {
fn get_index(entry: &OccupiedEntry<PackageName, PubGrubPriority>) -> Option<usize> {
match entry.get() {
PubGrubPriority::ConflictLate(Reverse(index)) => *index,
PubGrubPriority::Unspecified(Reverse(index)) => *index,
PubGrubPriority::ConflictEarly(Reverse(index)) => *index,
PubGrubPriority::Singleton(Reverse(index)) => *index,
PubGrubPriority::DirectUrl(Reverse(index)) => *index,
PubGrubPriority::Root => next,
PubGrubPriority::ConflictLate(Reverse(index))
| PubGrubPriority::Unspecified(Reverse(index))
| PubGrubPriority::ConflictEarly(Reverse(index))
| PubGrubPriority::Singleton(Reverse(index))
| PubGrubPriority::DirectUrl(Reverse(index)) => Some(*index),
PubGrubPriority::Root => None,
}
}

Expand All @@ -109,19 +109,19 @@ impl PubGrubPriorities {
let next = self.0.len();
let Some(name) = package.name_no_root() else {
// Not a correctness bug
assert!(
!cfg!(debug_assertions),
"URL packages must not be involved in conflict handling"
);
return false;
if cfg!(debug_assertions) {
panic!("URL packages must not be involved in conflict handling")
} else {
return false;
}
};
match self.0.entry(name.clone()) {
std::collections::hash_map::Entry::Occupied(mut entry) => {
if matches!(entry.get(), PubGrubPriority::ConflictEarly(_)) {
// Already in the right category
return false;
};
let index = Self::get_index(next, &mut entry);
let index = Self::get_index(&entry).unwrap_or(next);
entry.insert(PubGrubPriority::ConflictEarly(Reverse(index)));
true
}
Expand All @@ -136,11 +136,11 @@ impl PubGrubPriorities {
let next = self.0.len();
let Some(name) = package.name_no_root() else {
// Not a correctness bug
assert!(
!cfg!(debug_assertions),
"URL packages must not be involved in conflict handling"
);
return false;
if cfg!(debug_assertions) {
panic!("URL packages must not be involved in conflict handling")
} else {
return false;
}
};
match self.0.entry(name.clone()) {
std::collections::hash_map::Entry::Occupied(mut entry) => {
Expand All @@ -152,7 +152,7 @@ impl PubGrubPriorities {
// Already in the right category
return false;
};
let index = Self::get_index(next, &mut entry);
let index = Self::get_index(&entry).unwrap_or(next);
entry.insert(PubGrubPriority::ConflictLate(Reverse(index)));
true
}
Expand Down

0 comments on commit 3ff3d9e

Please sign in to comment.