Skip to content

Commit

Permalink
Rollup merge of rust-lang#40514 - stjepang:inline-then-ordering, r=al…
Browse files Browse the repository at this point in the history
…excrichton

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.
  • Loading branch information
frewsxcv authored Mar 15, 2017
2 parents e56ef86 + 8af3013 commit 51738b3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ impl Ordering {
///
/// assert_eq!(result, Ordering::Less);
/// ```
#[inline]
#[unstable(feature = "ordering_chaining", issue = "37053")]
pub fn then(self, other: Ordering) -> Ordering {
match self {
Expand Down Expand Up @@ -315,6 +316,7 @@ impl Ordering {
///
/// assert_eq!(result, Ordering::Less);
/// ```
#[inline]
#[unstable(feature = "ordering_chaining", issue = "37053")]
pub fn then_with<F: FnOnce() -> Ordering>(self, f: F) -> Ordering {
match self {
Expand Down

0 comments on commit 51738b3

Please sign in to comment.