GenericProjectManager: Speed up adding lots of files

This operation was slowed down by a function that inserted a new element
into a sorted list without making use of the fact that the list is
already sorted.
As a test case, I added my whole ~/dev directory with ca 600,000 source
files to a generic project. With this patch, the time spent on building
up the new list went down from 90 minutes to one second.

Task-number: QTCREATORBUG-20652
Change-Id: If537e58a73cc5f09bb45d47f0beb2925048a2b14
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-11-14 09:49:12 +01:00
parent 48247182ae
commit ecf0105287

View File

@@ -305,20 +305,27 @@ bool GenericBuildSystem::saveRawList(const QStringList &rawList, const QString &
static void insertSorted(QStringList *list, const QString &value)
{
int pos = Utils::indexOf(*list, [value](const QString &s) { return s > value; });
if (pos == -1)
const auto it = std::lower_bound(list->begin(), list->end(), value);
if (it == list->end())
list->append(value);
else
list->insert(pos, value);
else if (*it > value)
list->insert(it, value);
}
bool GenericBuildSystem::addFiles(Node *, const QStringList &filePaths, QStringList *)
{
QStringList newList = m_rawFileList;
const QDir baseDir(projectDirectory().toString());
QStringList newList = m_rawFileList;
if (filePaths.size() > m_rawFileList.size()) {
newList += transform(filePaths, [&baseDir](const QString &p) {
return baseDir.relativeFilePath(p);
});
sort(newList);
newList.erase(std::unique(newList.begin(), newList.end()), newList.end());
} else {
for (const QString &filePath : filePaths)
insertSorted(&newList, baseDir.relativeFilePath(filePath));
}
const auto includes = transform<QSet<QString>>(m_projectIncludePaths,
[](const HeaderPath &hp) { return hp.path; });