@@ -360,12 +360,18 @@ impl Ordering {
360
360
/// assert_eq!(Ordering::Equal.is_eq(), true);
361
361
/// assert_eq!(Ordering::Greater.is_eq(), false);
362
362
/// ```
363
- #[ inline]
363
+ #[ inline( always ) ]
364
364
#[ must_use]
365
365
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
366
366
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
367
367
pub const fn is_eq ( self ) -> bool {
368
- matches ! ( self , Equal )
368
+ // Implementation note: It appears (as of 2022-12) that LLVM has an
369
+ // easier time with a comparison against zero like this, as opposed
370
+ // to looking for the `Less` value (-1) specifically, maybe because
371
+ // it's not always obvious to it that -2 isn't possible.
372
+ // Thus this and its siblings below are written this way, rather
373
+ // than the potentially-more-obvious `matches!` version.
374
+ ( self as i8 ) == 0
369
375
}
370
376
371
377
/// Returns `true` if the ordering is not the `Equal` variant.
@@ -379,12 +385,12 @@ impl Ordering {
379
385
/// assert_eq!(Ordering::Equal.is_ne(), false);
380
386
/// assert_eq!(Ordering::Greater.is_ne(), true);
381
387
/// ```
382
- #[ inline]
388
+ #[ inline( always ) ]
383
389
#[ must_use]
384
390
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
385
391
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
386
392
pub const fn is_ne ( self ) -> bool {
387
- ! matches ! ( self , Equal )
393
+ ( self as i8 ) != 0
388
394
}
389
395
390
396
/// Returns `true` if the ordering is the `Less` variant.
@@ -398,12 +404,12 @@ impl Ordering {
398
404
/// assert_eq!(Ordering::Equal.is_lt(), false);
399
405
/// assert_eq!(Ordering::Greater.is_lt(), false);
400
406
/// ```
401
- #[ inline]
407
+ #[ inline( always ) ]
402
408
#[ must_use]
403
409
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
404
410
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
405
411
pub const fn is_lt ( self ) -> bool {
406
- matches ! ( self , Less )
412
+ ( self as i8 ) < 0
407
413
}
408
414
409
415
/// Returns `true` if the ordering is the `Greater` variant.
@@ -417,12 +423,12 @@ impl Ordering {
417
423
/// assert_eq!(Ordering::Equal.is_gt(), false);
418
424
/// assert_eq!(Ordering::Greater.is_gt(), true);
419
425
/// ```
420
- #[ inline]
426
+ #[ inline( always ) ]
421
427
#[ must_use]
422
428
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
423
429
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
424
430
pub const fn is_gt ( self ) -> bool {
425
- matches ! ( self , Greater )
431
+ ( self as i8 ) > 0
426
432
}
427
433
428
434
/// Returns `true` if the ordering is either the `Less` or `Equal` variant.
@@ -436,12 +442,12 @@ impl Ordering {
436
442
/// assert_eq!(Ordering::Equal.is_le(), true);
437
443
/// assert_eq!(Ordering::Greater.is_le(), false);
438
444
/// ```
439
- #[ inline]
445
+ #[ inline( always ) ]
440
446
#[ must_use]
441
447
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
442
448
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
443
449
pub const fn is_le ( self ) -> bool {
444
- ! matches ! ( self , Greater )
450
+ ( self as i8 ) <= 0
445
451
}
446
452
447
453
/// Returns `true` if the ordering is either the `Greater` or `Equal` variant.
@@ -455,12 +461,12 @@ impl Ordering {
455
461
/// assert_eq!(Ordering::Equal.is_ge(), true);
456
462
/// assert_eq!(Ordering::Greater.is_ge(), true);
457
463
/// ```
458
- #[ inline]
464
+ #[ inline( always ) ]
459
465
#[ must_use]
460
466
#[ rustc_const_stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
461
467
#[ stable( feature = "ordering_helpers" , since = "1.53.0" ) ]
462
468
pub const fn is_ge ( self ) -> bool {
463
- ! matches ! ( self , Less )
469
+ ( self as i8 ) >= 0
464
470
}
465
471
466
472
/// Reverses the `Ordering`.
@@ -1124,7 +1130,11 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
1124
1130
#[ must_use]
1125
1131
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1126
1132
fn lt ( & self , other : & Rhs ) -> bool {
1127
- matches ! ( self . partial_cmp( other) , Some ( Less ) )
1133
+ if let Some ( ordering) = self . partial_cmp ( other) {
1134
+ ordering. is_lt ( )
1135
+ } else {
1136
+ false
1137
+ }
1128
1138
}
1129
1139
1130
1140
/// This method tests less than or equal to (for `self` and `other`) and is used by the `<=`
@@ -1143,7 +1153,11 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
1143
1153
#[ must_use]
1144
1154
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1145
1155
fn le ( & self , other : & Rhs ) -> bool {
1146
- matches ! ( self . partial_cmp( other) , Some ( Less | Equal ) )
1156
+ if let Some ( ordering) = self . partial_cmp ( other) {
1157
+ ordering. is_le ( )
1158
+ } else {
1159
+ false
1160
+ }
1147
1161
}
1148
1162
1149
1163
/// This method tests greater than (for `self` and `other`) and is used by the `>` operator.
@@ -1161,7 +1175,11 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
1161
1175
#[ must_use]
1162
1176
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1163
1177
fn gt ( & self , other : & Rhs ) -> bool {
1164
- matches ! ( self . partial_cmp( other) , Some ( Greater ) )
1178
+ if let Some ( ordering) = self . partial_cmp ( other) {
1179
+ ordering. is_gt ( )
1180
+ } else {
1181
+ false
1182
+ }
1165
1183
}
1166
1184
1167
1185
/// This method tests greater than or equal to (for `self` and `other`) and is used by the `>=`
@@ -1180,7 +1198,11 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
1180
1198
#[ must_use]
1181
1199
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1182
1200
fn ge ( & self , other : & Rhs ) -> bool {
1183
- matches ! ( self . partial_cmp( other) , Some ( Greater | Equal ) )
1201
+ if let Some ( ordering) = self . partial_cmp ( other) {
1202
+ ordering. is_ge ( )
1203
+ } else {
1204
+ false
1205
+ }
1184
1206
}
1185
1207
}
1186
1208
0 commit comments