forked from qt-creator/qt-creator
AutoTest: Optimize TestCodeParser::scanForTests
In case of loading a Creator project, after the Scanning For Tests finished, the scanForTests() called by TestCodeParser::onFinished() freezed the main thread for about 1 second. In this case requestRemoval() signal was emitted nearly 1000 times. Optimize the internals: 1. Don't emit requestRemoval() for every single file but emit it just once passing a QSet<FilePath> instead. 2. Adapt some other callees and callers to work on QSet<FilePath> instead on a single FilePath. This change constraints the freeze to about 2 ms. Change-Id: If23b85b495c125d82eb3c8b5a6912349df122745 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -100,8 +100,8 @@ void TestTreeModel::setupParsingConnections()
|
||||
m_parser, &TestCodeParser::onCppDocumentUpdated, Qt::QueuedConnection);
|
||||
connect(cppMM, &CppEditor::CppModelManager::aboutToRemoveFiles,
|
||||
this, [this](const QStringList &files) {
|
||||
const FilePaths filesToRemove = FileUtils::toFilePathList(files);
|
||||
removeFiles(filesToRemove);
|
||||
markForRemoval(transform<QSet>(files, &FilePath::fromString));
|
||||
sweep();
|
||||
}, Qt::QueuedConnection);
|
||||
connect(cppMM, &CppEditor::CppModelManager::projectPartsUpdated,
|
||||
m_parser, &TestCodeParser::onProjectPartsUpdated);
|
||||
@@ -109,11 +109,11 @@ void TestTreeModel::setupParsingConnections()
|
||||
QmlJS::ModelManagerInterface *qmlJsMM = QmlJS::ModelManagerInterface::instance();
|
||||
connect(qmlJsMM, &QmlJS::ModelManagerInterface::documentUpdated,
|
||||
m_parser, &TestCodeParser::onQmlDocumentUpdated, Qt::QueuedConnection);
|
||||
connect(qmlJsMM,
|
||||
&QmlJS::ModelManagerInterface::aboutToRemoveFiles,
|
||||
this,
|
||||
&TestTreeModel::removeFiles,
|
||||
Qt::QueuedConnection);
|
||||
connect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
|
||||
this, [this](const FilePaths &filePaths) {
|
||||
markForRemoval(Utils::toSet(filePaths));
|
||||
sweep();
|
||||
}, Qt::QueuedConnection);
|
||||
connectionsInitialized = true;
|
||||
}
|
||||
|
||||
@@ -463,13 +463,6 @@ void TestTreeModel::clearFailedMarks()
|
||||
m_failedStateCache.clear();
|
||||
}
|
||||
|
||||
void TestTreeModel::removeFiles(const FilePaths &files)
|
||||
{
|
||||
for (const FilePath &file : files)
|
||||
markForRemoval(file);
|
||||
sweep();
|
||||
}
|
||||
|
||||
void TestTreeModel::markAllFrameworkItemsForRemoval()
|
||||
{
|
||||
for (TestTreeItem *frameworkRoot : frameworkRootNodes()) {
|
||||
@@ -479,15 +472,12 @@ void TestTreeModel::markAllFrameworkItemsForRemoval()
|
||||
}
|
||||
}
|
||||
|
||||
void TestTreeModel::markForRemoval(const FilePath &filePath)
|
||||
void TestTreeModel::markForRemoval(const QSet<Utils::FilePath> &filePaths)
|
||||
{
|
||||
if (filePath.isEmpty())
|
||||
return;
|
||||
|
||||
for (TestTreeItem *frameworkRoot : frameworkRootNodes()) {
|
||||
for (int childRow = frameworkRoot->childCount() - 1; childRow >= 0; --childRow) {
|
||||
TestTreeItem *child = frameworkRoot->childItem(childRow);
|
||||
child->markForRemovalRecursively(filePath);
|
||||
child->markForRemovalRecursively(filePaths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user