Skip to content

Commit b696870

Browse files
authored
simplify SourceID Ord/Eq (#14980)
### What does this PR try to resolve? This is a followup to #14800. Like that PR, this is a small incremental change that does not pull its own weight. If this PR is accepted, the next PR will unlock large performance wins. I am not posting them together because the logic of why this PR is correct is subtle and deserves to be discussed and reviewed without unrelated code changes. ### How should we test and review this PR? All tests pass on all commits. This **should** be reviewed one commit at a time. ### Additional information I pushed one commit at a time, so that CI can confirm that the assert (in the first commit) is never hit.
2 parents 83615cf + a84336e commit b696870

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/cargo/core/source_id.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -591,21 +591,10 @@ impl Ord for SourceId {
591591
return Ordering::Equal;
592592
}
593593

594-
// Sort first based on `kind`, deferring to the URL comparison below if
594+
// Sort first based on `kind`, deferring to the URL comparison if
595595
// the kinds are equal.
596-
match self.inner.kind.cmp(&other.inner.kind) {
597-
Ordering::Equal => {}
598-
other => return other,
599-
}
600-
601-
// If the `kind` and the `url` are equal, then for git sources we also
602-
// ensure that the canonical urls are equal.
603-
match (&self.inner.kind, &other.inner.kind) {
604-
(SourceKind::Git(_), SourceKind::Git(_)) => {
605-
self.inner.canonical_url.cmp(&other.inner.canonical_url)
606-
}
607-
_ => self.inner.url.cmp(&other.inner.url),
608-
}
596+
let ord_kind = self.inner.kind.cmp(&other.inner.kind);
597+
ord_kind.then_with(|| self.inner.canonical_url.cmp(&other.inner.canonical_url))
609598
}
610599
}
611600

0 commit comments

Comments
 (0)