┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2013-01-11 16:57:43 +0100
committerFrank Reininghaus <[email protected]>2013-01-11 16:57:43 +0100
commit2a7e8b41d31f6395f3ca3803ed82a9a8094dda22 (patch)
treebc59236d2cc38128f5b56515574d292652cd1c35
parentd7373195f0a4bc9ec22332ad5260aa22e556d2d5 (diff)
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
-rw-r--r--src/kitemviews/private/kfileitemmodelsortalgorithm.cpp13
1 files changed, 11 insertions, 2 deletions
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<KFileItemModel::ItemData*>::iterator begin,
QList<KFileItemModel::ItemData*>::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,