]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Only use parallel sorting when sorting by name
authorFrank Reininghaus <frank78ac@googlemail.com>
Fri, 11 Jan 2013 15:57:43 +0000 (16:57 +0100)
committerFrank Reininghaus <frank78ac@googlemail.com>
Fri, 11 Jan 2013 15:57:43 +0000 (16:57 +0100)
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

src/kitemviews/private/kfileitemmodelsortalgorithm.cpp

index 9588d19bf135678b98ed7d1a808e4286c47284b3..ab650efea1e66451309f542081ede7c83b31ae36 100644 (file)
@@ -26,8 +26,17 @@ void KFileItemModelSortAlgorithm::sort(KFileItemModel* model,
                                        QList<KFileItemModel::ItemData*>::iterator begin,
                                        QList<KFileItemModel::ItemData*>::iterator end)
 {
                                        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,
 }
 
 void KFileItemModelSortAlgorithm::sequentialSort(KFileItemModel* model,