-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
#66780 suggested an optimization for impl Ord for bool
, and it was implemented in #66881.
However, for some reason, impl PartialOrd for bool
was not optimized the same way:
Lines 1286 to 1300 in 1f7762b
impl Ord for bool { | |
#[inline] | |
fn cmp(&self, other: &bool) -> Ordering { | |
// Casting to i8's and converting the difference to an Ordering generates | |
// more optimal assembly. | |
// See <https://github.com/rust-lang/rust/issues/66780> for more info. | |
match (*self as i8) - (*other as i8) { | |
-1 => Less, | |
0 => Equal, | |
1 => Greater, | |
// SAFETY: bool as i8 returns 0 or 1, so the difference can't be anything else | |
_ => unsafe { unreachable_unchecked() }, | |
} | |
} | |
} |
Lines 1236 to 1241 in 1f7762b
impl PartialOrd for bool { | |
#[inline] | |
fn partial_cmp(&self, other: &bool) -> Option<Ordering> { | |
(*self as u8).partial_cmp(&(*other as u8)) | |
} | |
} |
It can be implemented in terms of Ord
:
impl PartialOrd for bool {
#[inline]
fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
Some(self.cmp(other))
}
}
Is this deliberate or just something that no-one noticed?
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.