Commit 715f00a9 authored by Frank Reininghaus's avatar Frank Reininghaus

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
parent 5ccc6c70
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment