Skip to content

Commit dcf5f2a

Browse files
committed
Auto merge of rust-lang#83819 - AngelicosPhosphoros:issue-73338-fix-partial-eq-impl, r=Mark-Simulacrum
Optimize jumps in PartialOrd le Closes rust-lang#73338 This change stops default implementation of `le()` method of PartialOrd from generating jumps.
2 parents 024bd26 + 284bf26 commit dcf5f2a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/src/cmp.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,8 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
981981
#[must_use]
982982
#[stable(feature = "rust1", since = "1.0.0")]
983983
fn le(&self, other: &Rhs) -> bool {
984-
matches!(self.partial_cmp(other), Some(Less | Equal))
984+
// Pattern `Some(Less | Eq)` optimizes worse than negating `None | Some(Greater)`.
985+
!matches!(self.partial_cmp(other), None | Some(Greater))
985986
}
986987

987988
/// This method tests greater than (for `self` and `other`) and is used by the `>` operator.

0 commit comments

Comments
 (0)