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:
Jarek Kobus
2021-03-09 13:53:34 +01:00
parent 9d9ac537e8
commit 3ab93592c3
2 changed files with 3 additions and 13 deletions

View File

@@ -86,7 +86,6 @@ void CppLocatorData::onAboutToRemoveFiles(const QStringList &files)
void CppLocatorData::flushPendingDocument(bool force) const
{
// TODO: move this off the UI thread and into a future.
QMutexLocker locker(&m_pendingDocumentsMutex);
if (!force && m_pendingDocuments.size() < MaxPendingDocuments)
return;
if (m_pendingDocuments.isEmpty())
@@ -98,12 +97,3 @@ void CppLocatorData::flushPendingDocument(bool force) const
m_pendingDocuments.clear();
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;
}

View File

@@ -46,8 +46,8 @@ class CppLocatorData : public QObject
public:
void filterAllFiles(IndexItem::Visitor func) const
{
flushPendingDocument(true);
QMutexLocker locker(&m_pendingDocumentsMutex);
flushPendingDocument(true);
QHash<QString, IndexItem::Ptr> infosByFile = m_infosByFile;
locker.unlock();
for (auto i = infosByFile.constBegin(), ei = infosByFile.constEnd(); i != ei; ++i)
@@ -60,13 +60,13 @@ public slots:
void onAboutToRemoveFiles(const QStringList &files);
private:
// Ensure to protect every call to this method with m_pendingDocumentsMutex
void flushPendingDocument(bool force) const;
QList<IndexItem::Ptr> allIndexItems(const QHash<QString, QList<IndexItem::Ptr>> &items) const;
mutable SearchSymbols m_search;
mutable QHash<QString, IndexItem::Ptr> m_infosByFile;
mutable QRecursiveMutex m_pendingDocumentsMutex;
mutable QMutex m_pendingDocumentsMutex;
mutable QVector<CPlusPlus::Document::Ptr> m_pendingDocuments;
};