From 903381a8982a0aefc7b1eba223f9ee38ded3f018 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Wed, 30 Oct 2013 17:48:32 +0100 Subject: Sort in items in two stages to speed up natural sorting Sort the items in a folder first according to their name, without doing a natural/locale-aware sorting. This is very fast, but the order of the items is then already close to the final order in most cases. The number of expensive natural comparisons required to sort the items is thus greatly reduced. In my experiments with a folder with 100,000 items, the time required to sort the files was reduced by 63% with this patch. REVIEW: 113485 --- src/kitemviews/kfileitemmodel.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/kitemviews/kfileitemmodel.cpp') diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index f21edbf4a..e2d0413a2 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -1036,6 +1036,14 @@ void KFileItemModel::insertItems(QList& newItems) m_groups.clear(); + if (m_naturalSorting) { + // Natural sorting of items can be very slow. However, it becomes much + // faster if the input sequence is already mostly sorted. Therefore, we + // first sort 'newItems' according to the QStrings returned by + // KFileItem::text() using QString::operator<(), which is quite fast. + parallelMergeSort(newItems.begin(), newItems.end(), nameLessThan, QThread::idealThreadCount()); + } + sort(newItems.begin(), newItems.end()); #ifdef KFILEITEMMODEL_DEBUG -- cgit v1.3