Commit 53db4575 authored by Daniel Teske's avatar Daniel Teske

ProjectFileVisitor: Make faster

Instead of checking if a file is unique with a O(n) operation per file,
do one pass at the end after sorting. This makes opening qtproject.pro
roughly ~7% faster.

Change-Id: If30bdeb8f72e5b28fb900e8e7a45bddb5f9f7822
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent ec54444b
......@@ -231,6 +231,14 @@ ProjectFilesVisitor::ProjectFilesVisitor(QmakeProjectFiles *files) :
{
}
namespace {
// uses std::unique, so takes a sorted list
void unique(QStringList &list)
{
list.erase(std::unique(list.begin(), list.end()), list.end());
}
}
void ProjectFilesVisitor::findProjectFiles(QmakeProFileNode *rootNode, QmakeProjectFiles *files)
{
files->clear();
......@@ -238,16 +246,18 @@ void ProjectFilesVisitor::findProjectFiles(QmakeProFileNode *rootNode, QmakeProj
rootNode->accept(&visitor);
for (int i = 0; i < FileTypeSize; ++i) {
Utils::sort(files->files[i]);
unique(files->files[i]);
Utils::sort(files->generatedFiles[i]);
unique(files->generatedFiles[i]);
}
Utils::sort(files->proFiles);
unique(files->proFiles);
}
void ProjectFilesVisitor::visitProjectNode(ProjectNode *projectNode)
{
const QString path = projectNode->path();
if (!m_files->proFiles.contains(path))
m_files->proFiles.append(path);
m_files->proFiles.append(path);
visitFolderNode(projectNode);
}
......@@ -260,8 +270,7 @@ void ProjectFilesVisitor::visitFolderNode(FolderNode *folderNode)
const QString path = fileNode->path();
const int type = fileNode->fileType();
QStringList &targetList = fileNode->isGenerated() ? m_files->generatedFiles[type] : m_files->files[type];
if (!targetList.contains(path))
targetList.push_back(path);
targetList.push_back(path);
}
}
......
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