┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2015-05-07 21:09:01 +0100
committerFrank Reininghaus <[email protected]>2015-05-07 22:14:00 +0200
commite69d3489751ea15c0477fe1d41fcc252c775d377 (patch)
treec8082bdf7dc464cd5b6c84ddc26f6cfad16682f4 /src/kitemviews
parent5bde333ca7e9c285f1101bac0434fb4e60b6d4d5 (diff)
Fix KFileItemModel performance regression
Commit 119f7a3f fixed a crash that was caused by the porting of the natural sorting code to QCollator. QCollator is not thread-safe, so every thread needs its own instance. However, that commit made every recursive call in the sorting code create a new deep-copied QCollator instance, which is quite expensive and thus made inserting any items into the model very slow (this could also be seen in the KFileItemModel benchmark). This commit avoids unnecessary QCollator copying by forcing all sorting functions which are called in the same thread to pass the 'lessThan' object by const reference, such that no unnecessary copying of that object, including a deep copy of the QCollator, takes place. REVIEW: 123620
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/private/kfileitemmodelsortalgorithm.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/kitemviews/private/kfileitemmodelsortalgorithm.h b/src/kitemviews/private/kfileitemmodelsortalgorithm.h
index 50db9900d..7c090db91 100644
--- a/src/kitemviews/private/kfileitemmodelsortalgorithm.h
+++ b/src/kitemviews/private/kfileitemmodelsortalgorithm.h
@@ -37,7 +37,7 @@
template <typename RandomAccessIterator, typename LessThan>
static void mergeSort(RandomAccessIterator begin,
RandomAccessIterator end,
- LessThan lessThan)
+ const LessThan& lessThan)
{
// The implementation is based on qStableSortHelper() from qalgorithms.h
// Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
@@ -99,7 +99,7 @@ template <typename RandomAccessIterator, typename LessThan>
static void merge(RandomAccessIterator begin,
RandomAccessIterator pivot,
RandomAccessIterator end,
- LessThan lessThan)
+ const LessThan& lessThan)
{
// The implementation is based on qMerge() from qalgorithms.h
// Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
@@ -124,12 +124,14 @@ static void merge(RandomAccessIterator begin,
if (len1 > len2) {
const int len1Half = len1 / 2;
firstCut = begin + len1Half;
- secondCut = std::lower_bound(pivot, end, *firstCut, lessThan);
+ secondCut = std::lower_bound<RandomAccessIterator,
+ decltype(*firstCut), const LessThan&>(pivot, end, *firstCut, lessThan);
len2Half = secondCut - pivot;
} else {
len2Half = len2 / 2;
secondCut = pivot + len2Half;
- firstCut = std::upper_bound(begin, pivot, *secondCut, lessThan);
+ firstCut = std::upper_bound<RandomAccessIterator,
+ decltype(*secondCut), const LessThan&>(begin, pivot, *secondCut, lessThan);
}
std::rotate(firstCut, pivot, secondCut);