Commit e5907eaf authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Speed up the identification of C++ files in the generic project

The previous method of identifying the files matching any C/C++ or
ObjC++ mime types somewhat naively searched through all mime-types
(especially for hard to identify files) and then checked whether the
returned mime type was part of a limited set. This takes too long for
large projects.

The new method only checks against the mime types we're actually looking
for.

Task-number: QTCREATORBUG-8625
Change-Id: I956f3653db6b961c5c814eed1a1a43ac8a118704
Reviewed-by: default avatarThorbjørn Lindeijer <bjorn@lindeijer.nl>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent fcb1693e
......@@ -59,6 +59,27 @@ using namespace ProjectExplorer;
namespace GenericProjectManager {
namespace Internal {
static QList<Core::MimeType> cppMimeTypes()
{
QStringList mimeTypesNames;
mimeTypesNames << QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)
<< QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE);
QList<Core::MimeType> mimeTypes;
const Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
foreach (const QString &typeName, mimeTypesNames) {
Core::MimeType mimeType = mimeDatabase->findByType(typeName);
if (!mimeType.isNull())
mimeTypes.append(mimeType);
}
return mimeTypes;
}
////////////////////////////////////////////////////////////////////////////////////
//
// GenericProject
......@@ -269,18 +290,17 @@ void GenericProject::refresh(RefreshOptions options)
// ### add _defines.
// Add any C/C++ files to be parsed
QStringList cppMimeTypes;
cppMimeTypes << QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)
<< QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE);
const Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
const QList<Core::MimeType> mimeTypes = cppMimeTypes();
QFileInfo fileInfo;
foreach (const QString &file, files()) {
const Core::MimeType mimeType = mimeDatabase->findByFile(QFileInfo(file));
if (cppMimeTypes.contains(mimeType.type()))
part->sourceFiles += file;
fileInfo.setFile(file);
foreach (const Core::MimeType &mimeType, mimeTypes) {
if (mimeType.matchesFile(fileInfo)) {
part->sourceFiles += file;
break;
}
}
}
QStringList filesToUpdate;
......
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