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: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
Nicolas Arnaud-Cormos
2012-01-08 16:00:32 +01:00
committed by Leandro Melo
parent ab8d39ace1
commit 4095b80793
2 changed files with 12 additions and 2 deletions

View File

@@ -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,9 +301,12 @@ 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
if (project) { if (project) {
@@ -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();
} }
} }

View File

@@ -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:
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