X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b4800d794ce2f900f64decdf4974cd3edffe9b67..df8d439c55ea62eeb109bf5ff8f55ae3f386dd70:/src/kitemviews/private/kfileitemmodelsortalgorithm.cpp diff --git a/src/kitemviews/private/kfileitemmodelsortalgorithm.cpp b/src/kitemviews/private/kfileitemmodelsortalgorithm.cpp index 63eaea557..ab650efea 100644 --- a/src/kitemviews/private/kfileitemmodelsortalgorithm.cpp +++ b/src/kitemviews/private/kfileitemmodelsortalgorithm.cpp @@ -26,8 +26,17 @@ void KFileItemModelSortAlgorithm::sort(KFileItemModel* model, QList::iterator begin, QList::iterator end) { - static const int numberOfThreads = QThread::idealThreadCount(); - parallelSort(model, begin, end, numberOfThreads); + if (model->sortRole() == model->roleForType(KFileItemModel::NameRole)) { + // Sorting by name can be expensive, in particular if natural sorting is + // enabled. Use all CPU cores to speed up the sorting process. + static const int numberOfThreads = QThread::idealThreadCount(); + parallelSort(model, begin, end, numberOfThreads); + } else { + // 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 + sequentialSort(model, begin, end); + } } void KFileItemModelSortAlgorithm::sequentialSort(KFileItemModel* model, @@ -43,8 +52,8 @@ void KFileItemModelSortAlgorithm::sequentialSort(KFileItemModel* model, } const QList::iterator middle = begin + span / 2; - sort(model, begin, middle); - sort(model, middle, end); + sequentialSort(model, begin, middle); + sequentialSort(model, middle, end); merge(model, begin, middle, end); }