Commit 32842e75 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Reduce calls to mime database.

...by removing the unneeded ProjectFileAdder. Its job is already done
earlier, so use the results.

Change-Id: Ifd865e6203ed6162a0d852c2128fb6d30208a52b
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent bbba9cca
......@@ -52,20 +52,22 @@ public:
{
using CppTools::ProjectFile;
QStringList cHeaders, cxxHeaders;
QVector<ProjectFile> cHeaders;
QVector<ProjectFile> cxxHeaders;
foreach (const QString &file, files) {
const ProjectFile::Kind kind = fileClassifier
? fileClassifier(file)
: ProjectFile::classify(file);
const ProjectFile projectFile(file, kind);
switch (kind) {
case ProjectFile::CSource: m_cSources += file; break;
case ProjectFile::CHeader: cHeaders += file; break;
case ProjectFile::CXXSource: m_cxxSources += file; break;
case ProjectFile::CXXHeader: cxxHeaders += file; break;
case ProjectFile::ObjCSource: m_objcSources += file; break;
case ProjectFile::ObjCXXSource: m_objcxxSources += file; break;
case ProjectFile::CSource: m_cSources += projectFile; break;
case ProjectFile::CHeader: cHeaders += projectFile; break;
case ProjectFile::CXXSource: m_cxxSources += projectFile; break;
case ProjectFile::CXXHeader: cxxHeaders += projectFile; break;
case ProjectFile::ObjCSource: m_objcSources += projectFile; break;
case ProjectFile::ObjCXXSource: m_objcxxSources += projectFile; break;
default:
continue;
}
......@@ -99,10 +101,10 @@ public:
bool hasObjcSources() const { return !m_objcSources.isEmpty(); }
bool hasObjcxxSources() const { return !m_objcxxSources.isEmpty(); }
QStringList cSources() const { return m_cSources; }
QStringList cxxSources() const { return m_cxxSources; }
QStringList objcSources() const { return m_objcSources; }
QStringList objcxxSources() const { return m_objcxxSources; }
QVector<ProjectFile> cSources() const { return m_cSources; }
QVector<ProjectFile> cxxSources() const { return m_cxxSources; }
QVector<ProjectFile> objcSources() const { return m_objcSources; }
QVector<ProjectFile> objcxxSources() const { return m_objcxxSources; }
bool hasMultipleParts() const { return m_partCount > 1; }
bool hasNoParts() const { return m_partCount == 0; }
......@@ -117,7 +119,10 @@ public:
private:
QString m_partName;
QStringList m_cSources, m_cxxSources, m_objcSources, m_objcxxSources;
QVector<ProjectFile> m_cSources;
QVector<ProjectFile> m_cxxSources;
QVector<ProjectFile> m_objcSources;
QVector<ProjectFile> m_objcxxSources;
int m_partCount;
};
} // anonymous namespace
......@@ -322,66 +327,14 @@ void ProjectPartBuilder::evaluateProjectPartToolchain(
projectPart->updateLanguageFeatures();
}
namespace Internal {
class ProjectFileAdder
{
public:
ProjectFileAdder(QVector<ProjectFile> &files);
~ProjectFileAdder();
bool maybeAdd(const QString &path);
private:
void addMapping(const char *mimeName, ProjectFile::Kind kind);
QVector<ProjectFile> &m_files;
QHash<QString, ProjectFile::Kind> m_mimeNameMapping;
};
ProjectFileAdder::ProjectFileAdder(QVector<ProjectFile> &files)
: m_files(files)
{
addMapping(CppTools::Constants::C_SOURCE_MIMETYPE, ProjectFile::CSource);
addMapping(CppTools::Constants::C_HEADER_MIMETYPE, ProjectFile::CHeader);
addMapping(CppTools::Constants::CPP_SOURCE_MIMETYPE, ProjectFile::CXXSource);
addMapping(CppTools::Constants::CPP_HEADER_MIMETYPE, ProjectFile::CXXHeader);
addMapping(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE, ProjectFile::ObjCSource);
addMapping(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE, ProjectFile::ObjCXXSource);
}
ProjectFileAdder::~ProjectFileAdder()
{
}
bool ProjectFileAdder::maybeAdd(const QString &path)
{
Utils::MimeDatabase mdb;
const Utils::MimeType mt = mdb.mimeTypeForFile(path);
if (m_mimeNameMapping.contains(mt.name())) {
m_files << ProjectFile(path, m_mimeNameMapping.value(mt.name()));
return true;
}
return false;
}
void ProjectFileAdder::addMapping(const char *mimeName, ProjectFile::Kind kind)
{
Utils::MimeDatabase mdb;
Utils::MimeType mimeType = mdb.mimeTypeForName(QLatin1String(mimeName));
if (mimeType.isValid())
m_mimeNameMapping.insert(mimeType.name(), kind);
}
}
void ProjectPartBuilder::createProjectPart(const QStringList &theSources,
void ProjectPartBuilder::createProjectPart(const QVector<ProjectFile> &theSources,
const QString &partName,
ProjectPart::LanguageVersion languageVersion,
ProjectPart::LanguageExtensions languageExtensions)
{
ProjectPart::Ptr part(m_templatePart->copy());
part->displayName = partName;
part->files = theSources;
QTC_ASSERT(part->project, return);
if (ProjectExplorer::Target *activeTarget = part->project->activeTarget()) {
......@@ -399,10 +352,6 @@ void ProjectPartBuilder::createProjectPart(const QStringList &theSources,
part->languageExtensions |= languageExtensions;
Internal::ProjectFileAdder adder(part->files);
foreach (const QString &file, theSources)
adder.maybeAdd(file);
m_pInfo.appendProjectPart(part);
}
......
......@@ -66,7 +66,8 @@ public:
const Utils::FileName &sysRoot);
private:
void createProjectPart(const QStringList &theSources, const QString &partName,
void createProjectPart(const QVector<ProjectFile> &theSources,
const QString &partName,
ProjectPart::LanguageVersion languageVersion,
ProjectPart::LanguageExtensions languageExtensions);
......
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