mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
A complete build does not fix the crashes I'm having.
I prefer to wait until QQCollator is thread safe or
someone discovers why this is happening now and not before.
Summary: This reverts commit 63825de82f
.
Test Plan: revert-hammer
Reviewers:
Subscribers:
This commit is contained in:
parent
63825de82f
commit
bd08aa09b2
|
@ -1709,24 +1709,63 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla
|
||||||
return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0;
|
return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for KFileItemModel::sort().
|
||||||
|
*/
|
||||||
|
class KFileItemModelLessThan
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KFileItemModelLessThan(const KFileItemModel* model, const QCollator& collator) :
|
||||||
|
m_model(model),
|
||||||
|
m_collator(collator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
KFileItemModelLessThan(const KFileItemModelLessThan& other) :
|
||||||
|
m_model(other.m_model),
|
||||||
|
m_collator()
|
||||||
|
{
|
||||||
|
m_collator.setCaseSensitivity(other.m_collator.caseSensitivity());
|
||||||
|
m_collator.setIgnorePunctuation(other.m_collator.ignorePunctuation());
|
||||||
|
m_collator.setLocale(other.m_collator.locale());
|
||||||
|
m_collator.setNumericMode(other.m_collator.numericMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
~KFileItemModelLessThan() = default;
|
||||||
|
//We do not delete m_model as the pointer was passed from outside ant it will be deleted elsewhere.
|
||||||
|
|
||||||
|
KFileItemModelLessThan& operator=(const KFileItemModelLessThan& other)
|
||||||
|
{
|
||||||
|
m_model = other.m_model;
|
||||||
|
m_collator = other.m_collator;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator()(const KFileItemModel::ItemData* a, const KFileItemModel::ItemData* b) const
|
||||||
|
{
|
||||||
|
return m_model->lessThan(a, b, m_collator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const KFileItemModel* m_model;
|
||||||
|
QCollator m_collator;
|
||||||
|
};
|
||||||
|
|
||||||
void KFileItemModel::sort(QList<KFileItemModel::ItemData*>::iterator begin,
|
void KFileItemModel::sort(QList<KFileItemModel::ItemData*>::iterator begin,
|
||||||
QList<KFileItemModel::ItemData*>::iterator end) const
|
QList<KFileItemModel::ItemData*>::iterator end) const
|
||||||
{
|
{
|
||||||
auto lambdaLessThan = [&] (const KFileItemModel::ItemData* a, const KFileItemModel::ItemData* b)
|
KFileItemModelLessThan lessThan(this, m_collator);
|
||||||
{
|
|
||||||
return lessThan(a, b, m_collator);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (m_sortRole == NameRole) {
|
if (m_sortRole == NameRole) {
|
||||||
// Sorting by name can be expensive, in particular if natural sorting is
|
// Sorting by name can be expensive, in particular if natural sorting is
|
||||||
// enabled. Use all CPU cores to speed up the sorting process.
|
// enabled. Use all CPU cores to speed up the sorting process.
|
||||||
static const int numberOfThreads = QThread::idealThreadCount();
|
static const int numberOfThreads = QThread::idealThreadCount();
|
||||||
parallelMergeSort(begin, end, lambdaLessThan, numberOfThreads);
|
parallelMergeSort(begin, end, lessThan, numberOfThreads);
|
||||||
} else {
|
} else {
|
||||||
// Sorting by other roles is quite fast. Use only one thread to prevent
|
// Sorting by other roles is quite fast. Use only one thread to prevent
|
||||||
// problems caused by non-reentrant comparison functions, see
|
// problems caused by non-reentrant comparison functions, see
|
||||||
// https://bugs.kde.org/show_bug.cgi?id=312679
|
// https://bugs.kde.org/show_bug.cgi?id=312679
|
||||||
mergeSort(begin, end, lambdaLessThan);
|
mergeSort(begin, end, lessThan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -499,6 +499,7 @@ private:
|
||||||
// and done step after step in slotCompleted().
|
// and done step after step in slotCompleted().
|
||||||
QSet<QUrl> m_urlsToExpand;
|
QSet<QUrl> m_urlsToExpand;
|
||||||
|
|
||||||
|
friend class KFileItemModelLessThan; // Accesses lessThan() method
|
||||||
friend class KFileItemModelRolesUpdater; // Accesses emitSortProgress() method
|
friend class KFileItemModelRolesUpdater; // Accesses emitSortProgress() method
|
||||||
friend class KFileItemModelTest; // For unit testing
|
friend class KFileItemModelTest; // For unit testing
|
||||||
friend class KFileItemModelBenchmark; // For unit testing
|
friend class KFileItemModelBenchmark; // For unit testing
|
||||||
|
|
Loading…
Reference in a new issue