Commit 4095b807 authored by Nicolas Arnaud-Cormos's avatar Nicolas Arnaud-Cormos Committed by Leandro Melo
Browse files

Add a cache for the header/source mapping.



Now that we are iterating all the files in the project (instead of stopping at
the first success), we need a cache to make the switching fast enough on big
projects.

Change-Id: Ib7d63c93b3303c534ca53856d96333a822046ced
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent ab8d39ac
...@@ -261,13 +261,16 @@ static int commonStringLength(const QString &s1, const QString &s2) ...@@ -261,13 +261,16 @@ static int commonStringLength(const QString &s1, const QString &s2)
QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) const QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) const
{ {
const QFileInfo fi(fileName);
if (m_headerSourceMapping.contains(fi.absoluteFilePath()))
return m_headerSourceMapping.value(fi.absoluteFilePath());
const Core::ICore *core = Core::ICore::instance(); const Core::ICore *core = Core::ICore::instance();
const Core::MimeDatabase *mimeDatase = core->mimeDatabase(); const Core::MimeDatabase *mimeDatase = core->mimeDatabase();
ProjectExplorer::ProjectExplorerPlugin *explorer = ProjectExplorer::ProjectExplorerPlugin *explorer =
ProjectExplorer::ProjectExplorerPlugin::instance(); ProjectExplorer::ProjectExplorerPlugin::instance();
ProjectExplorer::Project *project = (explorer ? explorer->currentProject() : 0); ProjectExplorer::Project *project = (explorer ? explorer->currentProject() : 0);
const QFileInfo fi(fileName);
const FileType type = fileType(mimeDatase, fi); const FileType type = fileType(mimeDatase, fi);
if (debug) if (debug)
...@@ -298,8 +301,11 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co ...@@ -298,8 +301,11 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co
// Try to find a file in the same directory first // Try to find a file in the same directory first
foreach (const QString &candidateFileName, candidateFileNames) { foreach (const QString &candidateFileName, candidateFileNames) {
const QFileInfo candidateFi(absoluteDir, candidateFileName); const QFileInfo candidateFi(absoluteDir, candidateFileName);
if (candidateFi.isFile()) if (candidateFi.isFile()) {
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
return candidateFi.absoluteFilePath(); return candidateFi.absoluteFilePath();
}
} }
// Find files in the project // Find files in the project
...@@ -320,6 +326,8 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co ...@@ -320,6 +326,8 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co
if (!bestFileName.isEmpty()) { if (!bestFileName.isEmpty()) {
const QFileInfo candidateFi(bestFileName); const QFileInfo candidateFi(bestFileName);
Q_ASSERT(candidateFi.isFile()); Q_ASSERT(candidateFi.isFile());
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
return candidateFi.absoluteFilePath(); return candidateFi.absoluteFilePath();
} }
} }
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <QtCore/QFutureInterface> #include <QtCore/QFutureInterface>
#include <QtCore/QPointer> #include <QtCore/QPointer>
#include <QtCore/QFutureWatcher> #include <QtCore/QFutureWatcher>
#include <QtCore/QHash>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QFileInfo; class QFileInfo;
...@@ -97,6 +98,7 @@ private: ...@@ -97,6 +98,7 @@ private:
CppModelManager *m_modelManager; CppModelManager *m_modelManager;
QSharedPointer<CppFileSettings> m_fileSettings; QSharedPointer<CppFileSettings> m_fileSettings;
CppToolsSettings *m_settings; CppToolsSettings *m_settings;
mutable QHash<QString, QString> m_headerSourceMapping;
}; };
} // namespace Internal } // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment