From: Frank Reininghaus Date: Fri, 11 Jan 2013 15:57:43 +0000 (+0100) Subject: Only use parallel sorting when sorting by name X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/2a7e8b41d31f6395f3ca3803ed82a9a8094dda22 Only use parallel sorting when sorting by name The reentrant natural comparison of strings is the only really expensive operation. Other comparison functions are much cheaper and might not be reentrant at all. Therefore, we disable parallel sorting when not sorting by name to prevent crashes and other unpleasant behaviour. BUG: 312679 FIXED-IN: 4.10 REVIEW: 108309 --- diff --git a/src/kitemviews/private/kfileitemmodelsortalgorithm.cpp b/src/kitemviews/private/kfileitemmodelsortalgorithm.cpp index 9588d19bf..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,