Skip to content

Commit f90fab5

Browse files
authored
Rollup merge of rust-lang#40514 - stjepang:inline-then-ordering, r=alexcrichton
Inline functions Ordering::{then, then_with} @jongiddy noticed bad performance due to the lack of inlining on `then` and `then_with`. I confirmed that inlining really is the culprit by creating a custom `then` function and repeating his benchmark on my machine with and without the `#[inline]` attribute. The numbers were exactly the same on my machine without the attribute. With `#[inline]` I got the same performance as I did with manually inlined implementation. The problem was reported in rust-lang#37053.
2 parents 1909b62 + 8af3013 commit f90fab5

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/libcore/cmp.rs

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ impl Ordering {
277277
///
278278
/// assert_eq!(result, Ordering::Less);
279279
/// ```
280+
#[inline]
280281
#[unstable(feature = "ordering_chaining", issue = "37053")]
281282
pub fn then(self, other: Ordering) -> Ordering {
282283
match self {
@@ -315,6 +316,7 @@ impl Ordering {
315316
///
316317
/// assert_eq!(result, Ordering::Less);
317318
/// ```
319+
#[inline]
318320
#[unstable(feature = "ordering_chaining", issue = "37053")]
319321
pub fn then_with<F: FnOnce() -> Ordering>(self, f: F) -> Ordering {
320322
match self {

0 commit comments

Comments
 (0)