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

sort: Fast path for already sorted data #29675

Merged
merged 2 commits into from
Nov 13, 2015

Commits on Nov 7, 2015

  1. sort: Fast path for already sorted data

    When merging two sorted blocks `left` and `right` if the last element in
    `left` is <= the first in `right`, the blocks are already sorted.
    
    Add this as an additional fast path by simply copying the whole left
    block into the output and advancing the left pointer. The right block is
    then treated the same way by the already present logic in the merge
    loop.
    
    Reduces runtime of .sort() to less than 50% of the previous, if the data
    was already perfectly sorted. Sorted data with a few swaps are also
    sorted quicker than before. The overhead of one comparison per merge
    seems to be negligible.
    bluss committed Nov 7, 2015
    Configuration menu
    Copy the full SHA
    35fd1ba View commit details
    Browse the repository at this point in the history
  2. sort: Guard the fast path by length check

    The right part must not be empty.
    bluss committed Nov 7, 2015
    Configuration menu
    Copy the full SHA
    0f5e30d View commit details
    Browse the repository at this point in the history