forked from qt-creator/qt-creator
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: Thorbjørn Lindeijer <bjorn@lindeijer.nl> Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -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 QList<Core::MimeType> mimeTypes = cppMimeTypes();
|
||||
QFileInfo fileInfo;
|
||||
|
||||
const Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
|
||||
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;
|
||||
|
Reference in New Issue
Block a user