forked from qt-creator/qt-creator
CppLocatorData: Don't use recursive mutex
Don't use recursive mutex in CppLocatorData class, as this is more expensive to construct than simple QMutex. Refactor the code so that every call to flushPendingDocument() is done with already locked m_pendingDocumentsMutex. This eliminates the need for recursive mutex. Remove unused allIndexItems() method. Change-Id: Ic7cb45bc3301d83768e69ee52f84ae159cb731a5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -86,7 +86,6 @@ void CppLocatorData::onAboutToRemoveFiles(const QStringList &files)
|
|||||||
void CppLocatorData::flushPendingDocument(bool force) const
|
void CppLocatorData::flushPendingDocument(bool force) const
|
||||||
{
|
{
|
||||||
// TODO: move this off the UI thread and into a future.
|
// TODO: move this off the UI thread and into a future.
|
||||||
QMutexLocker locker(&m_pendingDocumentsMutex);
|
|
||||||
if (!force && m_pendingDocuments.size() < MaxPendingDocuments)
|
if (!force && m_pendingDocuments.size() < MaxPendingDocuments)
|
||||||
return;
|
return;
|
||||||
if (m_pendingDocuments.isEmpty())
|
if (m_pendingDocuments.isEmpty())
|
||||||
@@ -98,12 +97,3 @@ void CppLocatorData::flushPendingDocument(bool force) const
|
|||||||
m_pendingDocuments.clear();
|
m_pendingDocuments.clear();
|
||||||
m_pendingDocuments.reserve(MaxPendingDocuments);
|
m_pendingDocuments.reserve(MaxPendingDocuments);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IndexItem::Ptr> CppLocatorData::allIndexItems(
|
|
||||||
const QHash<QString, QList<IndexItem::Ptr>> &items) const
|
|
||||||
{
|
|
||||||
QList<IndexItem::Ptr> result;
|
|
||||||
for (const QList<IndexItem::Ptr> &subItems : items)
|
|
||||||
result.append(subItems);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
@@ -46,8 +46,8 @@ class CppLocatorData : public QObject
|
|||||||
public:
|
public:
|
||||||
void filterAllFiles(IndexItem::Visitor func) const
|
void filterAllFiles(IndexItem::Visitor func) const
|
||||||
{
|
{
|
||||||
flushPendingDocument(true);
|
|
||||||
QMutexLocker locker(&m_pendingDocumentsMutex);
|
QMutexLocker locker(&m_pendingDocumentsMutex);
|
||||||
|
flushPendingDocument(true);
|
||||||
QHash<QString, IndexItem::Ptr> infosByFile = m_infosByFile;
|
QHash<QString, IndexItem::Ptr> infosByFile = m_infosByFile;
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
for (auto i = infosByFile.constBegin(), ei = infosByFile.constEnd(); i != ei; ++i)
|
for (auto i = infosByFile.constBegin(), ei = infosByFile.constEnd(); i != ei; ++i)
|
||||||
@@ -60,13 +60,13 @@ public slots:
|
|||||||
void onAboutToRemoveFiles(const QStringList &files);
|
void onAboutToRemoveFiles(const QStringList &files);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Ensure to protect every call to this method with m_pendingDocumentsMutex
|
||||||
void flushPendingDocument(bool force) const;
|
void flushPendingDocument(bool force) const;
|
||||||
QList<IndexItem::Ptr> allIndexItems(const QHash<QString, QList<IndexItem::Ptr>> &items) const;
|
|
||||||
|
|
||||||
mutable SearchSymbols m_search;
|
mutable SearchSymbols m_search;
|
||||||
mutable QHash<QString, IndexItem::Ptr> m_infosByFile;
|
mutable QHash<QString, IndexItem::Ptr> m_infosByFile;
|
||||||
|
|
||||||
mutable QRecursiveMutex m_pendingDocumentsMutex;
|
mutable QMutex m_pendingDocumentsMutex;
|
||||||
mutable QVector<CPlusPlus::Document::Ptr> m_pendingDocuments;
|
mutable QVector<CPlusPlus::Document::Ptr> m_pendingDocuments;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user