mirror of https://github.com/PrimeDecomp/prime.git
rstl::sort is just a few regswaps away
This commit is contained in:
parent
5af3c20f3c
commit
ef221d5c96
|
@ -72,23 +72,21 @@ void sort(It first, It last, Cmp cmp) {
|
||||||
if (count <= 20) {
|
if (count <= 20) {
|
||||||
__insertion_sort(first, last, cmp);
|
__insertion_sort(first, last, cmp);
|
||||||
} else {
|
} else {
|
||||||
It beforeLast = last - 1;
|
It end = last;
|
||||||
It middle = first + count / 2;
|
__sort3(*first, *(first + count / 2), *--end, cmp);
|
||||||
__sort3(*first, *middle, *(last - 1), cmp);
|
typename iterator_traits< It >::value_type value = *(first + count / 2);
|
||||||
|
|
||||||
typename iterator_traits< It >::value_type value = *middle;
|
|
||||||
It it = first + 1;
|
It it = first + 1;
|
||||||
|
--end;
|
||||||
while (true) {
|
while (true) {
|
||||||
while (cmp(*it, value))
|
while (cmp(*it, value))
|
||||||
++it;
|
++it;
|
||||||
while (cmp(value, *beforeLast))
|
while (cmp(value, *end))
|
||||||
--beforeLast;
|
--end;
|
||||||
if (it >= beforeLast)
|
if (it >= end)
|
||||||
break;
|
break;
|
||||||
iter_swap(beforeLast, it); // wrong order?
|
iter_swap(it, end);
|
||||||
++it;
|
++it;
|
||||||
--beforeLast;
|
--end;
|
||||||
}
|
}
|
||||||
sort(first, it, cmp);
|
sort(first, it, cmp);
|
||||||
sort(it, last, cmp);
|
sort(it, last, cmp);
|
||||||
|
|
Loading…
Reference in New Issue