Remove extra compare in rstl::sort

Former-commit-id: 8c999d9a88
This commit is contained in:
Henrique Gemignani Passos Lima 2022-11-27 18:02:31 +02:00
parent b97f9c56de
commit 2438238eb5
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); __insertion_sort(first, last, cmp);
} else { } else {
It beforeLast = last - 1; It beforeLast = last - 1;
__sort3(*first, *(first + count / 2), *(last - 1), cmp);
It middle = first + count / 2; It middle = first + count / 2;
__sort3(*first, *middle, *(last - 1), cmp);
typename iterator_traits< It >::value_type value = *middle;
It it = first + 1; It it = first + 1;
while (true) { 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; break;
rstl::swap(*it, *beforeLast); rstl::swap(*it, *beforeLast);
++it; ++it;