diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -1735,7 +1735,7 @@ // Sorting by other roles is quite fast. Use only one thread to prevent // problems caused by non-reentrant comparison functions, see // https://bugs.kde.org/show_bug.cgi?id=312679 - mergeSort(begin, end, lambdaLessThan); + std::stable_sort(begin, end, lambdaLessThan); } } diff --git a/src/kitemviews/private/kfileitemmodelsortalgorithm.h b/src/kitemviews/private/kfileitemmodelsortalgorithm.h --- a/src/kitemviews/private/kfileitemmodelsortalgorithm.h +++ b/src/kitemviews/private/kfileitemmodelsortalgorithm.h @@ -26,33 +26,6 @@ #include -/** - * Sorts the items using the merge sort algorithm is used to assure a - * worst-case of O(n * log(n)) and to keep the number of comparisons low. - * - * The implementation is based on qStableSortHelper() from qalgorithms.h - * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - */ - -template -static void mergeSort(RandomAccessIterator begin, - RandomAccessIterator end, - const LessThan& lessThan) -{ - // The implementation is based on qStableSortHelper() from qalgorithms.h - // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - - const int span = end - begin; - if (span < 2) { - return; - } - - const RandomAccessIterator middle = begin + span / 2; - mergeSort(begin, middle, lessThan); - mergeSort(middle, end, lessThan); - merge(begin, middle, end, lessThan); -} - /** * Uses up to \a numberOfThreads threads to sort the items between * \a begin and \a end. Only item ranges longer than @@ -82,7 +55,7 @@ merge(begin, middle, end, lessThan); } else { - mergeSort(begin, end, lessThan); + std::stable_sort(begin, end, lessThan); } } diff --git a/src/tests/dolphinsortingbenchmark.cpp b/src/tests/dolphinsortingbenchmark.cpp --- a/src/tests/dolphinsortingbenchmark.cpp +++ b/src/tests/dolphinsortingbenchmark.cpp @@ -51,7 +51,7 @@ std::vector v(1000); std::generate(v.begin(), v.end(), std::rand); // rand isn't a great random number generator, but should be fine for the benchmark QBENCHMARK { - mergeSort(v.begin(), v.end(), [](int a, int b){return a < b;}); + std::stable_sort(v.begin(), v.end(), [](int a, int b){return a < b;}); } qDebug() << std::is_sorted(v.begin(), v.end()); // this is intended as an optimization barrier } @@ -65,7 +65,7 @@ { QFETCH(QStringList, strings); QBENCHMARK { - mergeSort(strings.begin(), strings.end(), std::less_equal{}); + std::stable_sort(strings.begin(), strings.end(), std::less_equal{}); } QVERIFY(std::is_sorted(strings.begin(), strings.end())); }