Remove extra compare in rstl::sort

This commit is contained in:
Henrique Gemignani Passos Lima 2022-11-27 18:02:31 +02:00
parent 714e3dea7e
commit 8c999d9a88
No known key found for this signature in database
GPG Key ID: E224F951761145F8
1 changed files with 6 additions and 5 deletions

View File

@ -73,17 +73,18 @@ void sort(It first, It last, Cmp cmp) {
__insertion_sort(first, last, cmp);
} else {
It beforeLast = last - 1;
__sort3(*first, *(first + count / 2), *(last - 1), cmp);
It middle = first + count / 2;
__sort3(*first, *middle, *(last - 1), cmp);
typename iterator_traits< It >::value_type value = *middle;
It it = first + 1;
while (true) {
for (; cmp(*it, *middle); ++it)
for (; cmp(*it, value); ++it)
;
for (; cmp(*middle, *beforeLast); --beforeLast)
for (; cmp(value, *beforeLast); --beforeLast)
;
if (!cmp(*it, *beforeLast))
if (it > beforeLast)
break;
rstl::swap(*it, *beforeLast);
++it;