Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialize PartialOrd<A> for [A] where A: Ord #39642

Merged
merged 3 commits into from Feb 11, 2017
Merged

Specialize PartialOrd<A> for [A] where A: Ord #39642

merged 3 commits into from Feb 11, 2017

Commits on Feb 8, 2017

  1. Specialize PartialOrd<A> for [A] where A: Ord

    This way we can call `cmp` instead of `partial_cmp` in the loop,
    removing some burden of optimizing `Option`s away from the compiler.
    
    PR #39538 introduced a regression where sorting slices suddenly became
    slower, since `slice1.lt(slice2)` was much slower than
    `slice1.cmp(slice2) == Less`. This problem is now fixed.
    
    To verify, I benchmarked this simple program:
    ```rust
    fn main() {
        let mut v = (0..2_000_000).map(|x| x * x * x * 18913515181).map(|x| vec![x, x ^ 3137831591]).collect::<Vec<_>>();
        v.sort();
    }
    ```
    
    Before this PR, it would take 0.95 sec, and now it takes 0.58 sec.
    I also tried changing the `is_less` lambda to use `cmp` and
    `partial_cmp`. Now all three versions (`lt`, `cmp`, `partial_cmp`) are
    equally performant for sorting slices - all of them take 0.58 sec on the
    benchmark.
    Stjepan Glavina committed Feb 8, 2017
    Configuration menu
    Copy the full SHA
    3bd6e46 View commit details
    Browse the repository at this point in the history
  2. Simplify by calling SliceOrd::compare

    Stjepan Glavina committed Feb 8, 2017
    Configuration menu
    Copy the full SHA
    ececbb2 View commit details
    Browse the repository at this point in the history
  3. Remove unnecessary specialization for [u8]

    Stjepan Glavina committed Feb 8, 2017
    Configuration menu
    Copy the full SHA
    a344c12 View commit details
    Browse the repository at this point in the history