Skip to content

Commit

Permalink
This is 3% faster because of better use of speculative hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
andralex committed Aug 12, 2016
1 parent 30cb519 commit 66ba7b8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions std/algorithm/sorting.d
Original file line number Diff line number Diff line change
Expand Up @@ -1340,12 +1340,16 @@ private void quickSortImpl(alias less, Range)(Range r, size_t depth)
r.swapAt(pivotIdx, r.length - 1);
size_t lessI = size_t.max, greaterI = r.length - 1;

while (true)
outer: for (;;)
{
alias pred = binaryFun!less;
while (pred(r[++lessI], pivot)) {}
assert(lessI <= greaterI, "sort: invalid comparison function.");
while (greaterI > lessI && pred(pivot, r[--greaterI])) {}
for (;;)
{
if (greaterI == lessI) break outer;
if (!pred(pivot, r[--greaterI])) break;
}
assert(lessI <= greaterI, "sort: invalid comparison function.");
if (lessI == greaterI) break;
r.swapAt(lessI, greaterI);
Expand Down

0 comments on commit 66ba7b8

Please sign in to comment.