forked from qt-creator/qt-creator
CppModelManager: reduce number of cleanPath calls.
Instead of checking each file's full path individually we store the cleaned version of the directory. Change-Id: Icaa41a38d6608ba364fcb0e01cc9eb1db99470ac Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com> Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -234,10 +234,8 @@ void CppPreprocessor::setIncludePaths(const QStringList &includePaths)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_includePaths.append(path);
|
|
||||||
} else {
|
|
||||||
m_includePaths.append(path);
|
|
||||||
}
|
}
|
||||||
|
m_includePaths.append(cleanPath(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,11 +260,11 @@ void CppPreprocessor::addFrameworkPath(const QString &frameworkPath)
|
|||||||
// The algorithm below is a bit too eager, but that's because we're not getting
|
// The algorithm below is a bit too eager, but that's because we're not getting
|
||||||
// in the frameworks we're linking against. If we would have that, then we could
|
// in the frameworks we're linking against. If we would have that, then we could
|
||||||
// add only those private frameworks.
|
// add only those private frameworks.
|
||||||
if (!m_frameworkPaths.contains(frameworkPath)) {
|
QString cleanFrameworkPath = cleanPath(frameworkPath);
|
||||||
m_frameworkPaths.append(frameworkPath);
|
if (!m_frameworkPaths.contains(cleanFrameworkPath))
|
||||||
}
|
m_frameworkPaths.append(cleanFrameworkPath);
|
||||||
|
|
||||||
const QDir frameworkDir(frameworkPath);
|
const QDir frameworkDir(cleanFrameworkPath);
|
||||||
const QStringList filter = QStringList() << QLatin1String("*.framework");
|
const QStringList filter = QStringList() << QLatin1String("*.framework");
|
||||||
foreach (const QFileInfo &framework, frameworkDir.entryInfoList(filter)) {
|
foreach (const QFileInfo &framework, frameworkDir.entryInfoList(filter)) {
|
||||||
if (!framework.isDir())
|
if (!framework.isDir())
|
||||||
@@ -385,10 +383,13 @@ QString CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type, uns
|
|||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void appendDirSeparatorIfNeeded(QString &path)
|
QString CppPreprocessor::cleanPath(const QString &path)
|
||||||
{
|
{
|
||||||
if (!path.endsWith(QLatin1Char('/'), Qt::CaseInsensitive))
|
QString result = QDir::cleanPath(path);
|
||||||
path += QLatin1Char('/');
|
const QChar slash(QLatin1Char('/'));
|
||||||
|
if (!result.endsWith(slash))
|
||||||
|
result.append(slash);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CppPreprocessor::tryIncludeFile_helper(QString &fileName, IncludeType type, unsigned *revision)
|
QString CppPreprocessor::tryIncludeFile_helper(QString &fileName, IncludeType type, unsigned *revision)
|
||||||
@@ -402,10 +403,7 @@ QString CppPreprocessor::tryIncludeFile_helper(QString &fileName, IncludeType ty
|
|||||||
|
|
||||||
if (type == IncludeLocal && m_currentDoc) {
|
if (type == IncludeLocal && m_currentDoc) {
|
||||||
QFileInfo currentFileInfo(m_currentDoc->fileName());
|
QFileInfo currentFileInfo(m_currentDoc->fileName());
|
||||||
QString path = currentFileInfo.absolutePath();
|
QString path = cleanPath(currentFileInfo.absolutePath()) + fileName;
|
||||||
appendDirSeparatorIfNeeded(path);
|
|
||||||
path += fileName;
|
|
||||||
path = QDir::cleanPath(path);
|
|
||||||
QString contents;
|
QString contents;
|
||||||
if (includeFile(path, &contents, revision)) {
|
if (includeFile(path, &contents, revision)) {
|
||||||
fileName = path;
|
fileName = path;
|
||||||
@@ -414,23 +412,7 @@ QString CppPreprocessor::tryIncludeFile_helper(QString &fileName, IncludeType ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (const QString &includePath, m_includePaths) {
|
foreach (const QString &includePath, m_includePaths) {
|
||||||
QString path = includePath;
|
QString path = includePath + fileName;
|
||||||
appendDirSeparatorIfNeeded(path);
|
|
||||||
path += fileName;
|
|
||||||
path = QDir::cleanPath(path);
|
|
||||||
QString contents;
|
|
||||||
if (includeFile(path, &contents, revision)) {
|
|
||||||
fileName = path;
|
|
||||||
return contents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// look in the system include paths
|
|
||||||
foreach (const QString &includePath, m_systemIncludePaths) {
|
|
||||||
QString path = includePath;
|
|
||||||
appendDirSeparatorIfNeeded(path);
|
|
||||||
path += fileName;
|
|
||||||
path = QDir::cleanPath(path);
|
|
||||||
QString contents;
|
QString contents;
|
||||||
if (includeFile(path, &contents, revision)) {
|
if (includeFile(path, &contents, revision)) {
|
||||||
fileName = path;
|
fileName = path;
|
||||||
@@ -441,15 +423,10 @@ QString CppPreprocessor::tryIncludeFile_helper(QString &fileName, IncludeType ty
|
|||||||
int index = fileName.indexOf(QLatin1Char('/'));
|
int index = fileName.indexOf(QLatin1Char('/'));
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
QString frameworkName = fileName.left(index);
|
QString frameworkName = fileName.left(index);
|
||||||
QString name = fileName.mid(index + 1);
|
QString name = frameworkName + QLatin1String(".framework/Headers/") + fileName.mid(index + 1);
|
||||||
|
|
||||||
foreach (const QString &frameworkPath, m_frameworkPaths) {
|
foreach (const QString &frameworkPath, m_frameworkPaths) {
|
||||||
QString path = frameworkPath;
|
QString path = frameworkPath + name;
|
||||||
appendDirSeparatorIfNeeded(path);
|
|
||||||
path += frameworkName;
|
|
||||||
path += QLatin1String(".framework/Headers/");
|
|
||||||
path += name;
|
|
||||||
path = QDir::cleanPath(path);
|
|
||||||
QString contents;
|
QString contents;
|
||||||
if (includeFile(path, &contents, revision)) {
|
if (includeFile(path, &contents, revision)) {
|
||||||
fileName = path;
|
fileName = path;
|
||||||
@@ -458,19 +435,6 @@ QString CppPreprocessor::tryIncludeFile_helper(QString &fileName, IncludeType ty
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString path = fileName;
|
|
||||||
if (path.at(0) != QLatin1Char('/'))
|
|
||||||
path.prepend(QLatin1Char('/'));
|
|
||||||
|
|
||||||
foreach (const QString &projectFile, m_projectFiles) {
|
|
||||||
if (projectFile.endsWith(path)) {
|
|
||||||
fileName = projectFile;
|
|
||||||
QString contents;
|
|
||||||
includeFile(fileName, &contents, revision);
|
|
||||||
return contents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//qDebug() << "**** file" << fileName << "not found!";
|
//qDebug() << "**** file" << fileName << "not found!";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@@ -794,7 +758,8 @@ QStringList CppModelManager::internalIncludePaths() const
|
|||||||
it.next();
|
it.next();
|
||||||
ProjectInfo pinfo = it.value();
|
ProjectInfo pinfo = it.value();
|
||||||
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
|
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
|
||||||
includePaths += part->includePaths;
|
foreach (const QString &path, part->includePaths)
|
||||||
|
includePaths.append(CppPreprocessor::cleanPath(path));
|
||||||
}
|
}
|
||||||
includePaths.removeDuplicates();
|
includePaths.removeDuplicates();
|
||||||
return includePaths;
|
return includePaths;
|
||||||
@@ -808,7 +773,8 @@ QStringList CppModelManager::internalFrameworkPaths() const
|
|||||||
it.next();
|
it.next();
|
||||||
ProjectInfo pinfo = it.value();
|
ProjectInfo pinfo = it.value();
|
||||||
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
|
foreach (const ProjectPart::Ptr &part, pinfo.projectParts())
|
||||||
frameworkPaths += part->frameworkPaths;
|
foreach (const QString &path, part->frameworkPaths)
|
||||||
|
frameworkPaths.append(CppPreprocessor::cleanPath(path));
|
||||||
}
|
}
|
||||||
frameworkPaths.removeDuplicates();
|
frameworkPaths.removeDuplicates();
|
||||||
return frameworkPaths;
|
return frameworkPaths;
|
||||||
|
@@ -265,6 +265,7 @@ public:
|
|||||||
void run(const QString &fileName);
|
void run(const QString &fileName);
|
||||||
|
|
||||||
void resetEnvironment();
|
void resetEnvironment();
|
||||||
|
static QString cleanPath(const QString &path);
|
||||||
|
|
||||||
const QSet<QString> &todo() const
|
const QSet<QString> &todo() const
|
||||||
{ return m_todo; }
|
{ return m_todo; }
|
||||||
@@ -305,7 +306,6 @@ private:
|
|||||||
CPlusPlus::Environment env;
|
CPlusPlus::Environment env;
|
||||||
CPlusPlus::Preprocessor preprocess;
|
CPlusPlus::Preprocessor preprocess;
|
||||||
QStringList m_includePaths;
|
QStringList m_includePaths;
|
||||||
QStringList m_systemIncludePaths;
|
|
||||||
CPlusPlus::CppModelManagerInterface::WorkingCopy m_workingCopy;
|
CPlusPlus::CppModelManagerInterface::WorkingCopy m_workingCopy;
|
||||||
QStringList m_projectFiles;
|
QStringList m_projectFiles;
|
||||||
QStringList m_frameworkPaths;
|
QStringList m_frameworkPaths;
|
||||||
|
Reference in New Issue
Block a user