AutoTest: Avoid using costly containers

Replace several occurrences of QMap with QHash as we often do
not care about the order and use iterators instead of fetching
keys or values to iterate over them.

Change-Id: I5061a7e7e60fe259ac2aa31915f338a373e278d3
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2016-03-09 08:17:33 +01:00
parent 58654c134e
commit f34bb5e81c
3 changed files with 51 additions and 39 deletions

View File

@@ -507,7 +507,7 @@ static void handleGTest(QFutureInterface<TestParseResult> futureInterface, const
static void checkDocumentForTestCode(QFutureInterface<TestParseResult> futureInterface, static void checkDocumentForTestCode(QFutureInterface<TestParseResult> futureInterface,
CPlusPlus::Document::Ptr document, CPlusPlus::Document::Ptr document,
QMap<QString, QString> testCaseNames) QHash<QString, QString> testCaseNames)
{ {
const QString fileName = document->fileName(); const QString fileName = document->fileName();
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
@@ -567,7 +567,7 @@ static void checkDocumentForTestCode(QFutureInterface<TestParseResult> futureInt
static bool parsingHasFailed; static bool parsingHasFailed;
static void performParse(QFutureInterface<TestParseResult> &futureInterface, static void performParse(QFutureInterface<TestParseResult> &futureInterface,
const QStringList &list, const QMap<QString, QString> testCaseNames) const QStringList &list, const QHash<QString, QString> testCaseNames)
{ {
int progressValue = 0; int progressValue = 0;
futureInterface.setProgressRange(0, list.size()); futureInterface.setProgressRange(0, list.size());
@@ -718,7 +718,7 @@ void TestCodeParser::scanForTests(const QStringList &fileList)
parsingHasFailed = false; parsingHasFailed = false;
QMap<QString, QString> testCaseNames; QHash<QString, QString> testCaseNames;
if (isFullParse) { if (isFullParse) {
// remove qml files as they will be found automatically by the referencing cpp file // remove qml files as they will be found automatically by the referencing cpp file
list = Utils::filtered(list, [] (const QString &fn) { list = Utils::filtered(list, [] (const QString &fn) {

View File

@@ -253,7 +253,7 @@ QList<TestConfiguration *> TestTreeModel::getAllTestCases() const
} }
// get all Quick Tests // get all Quick Tests
QMap<QString, int> foundProFiles; QHash<QString, int> foundProFiles;
for (int row = 0, count = m_quickTestRootItem->childCount(); row < count; ++row) { for (int row = 0, count = m_quickTestRootItem->childCount(); row < count; ++row) {
const TestTreeItem *child = m_quickTestRootItem->childItem(row); const TestTreeItem *child = m_quickTestRootItem->childItem(row);
// unnamed Quick Tests must be handled separately // unnamed Quick Tests must be handled separately
@@ -270,13 +270,16 @@ QList<TestConfiguration *> TestTreeModel::getAllTestCases() const
foundProFiles.insert(proFile, foundProFiles[proFile] + child->childCount()); foundProFiles.insert(proFile, foundProFiles[proFile] + child->childCount());
} }
// create TestConfiguration for each project file // create TestConfiguration for each project file
foreach (const QString &proFile, foundProFiles.keys()) { {
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), QHash<QString, int>::ConstIterator it = foundProFiles.begin();
foundProFiles.value(proFile)); QHash<QString, int>::ConstIterator end = foundProFiles.end();
tc->setProFile(proFile); for ( ; it != end; ++it) {
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
tc->setProFile(it.key());
tc->setProject(project); tc->setProject(project);
result << tc; result << tc;
} }
}
foundProFiles.clear(); foundProFiles.clear();
@@ -298,8 +301,9 @@ QList<TestConfiguration *> TestTreeModel::getAllTestCases() const
} }
} }
QHash<ProFileWithDisplayName, int>::Iterator it = proFilesWithTestSets.begin(); {
QHash<ProFileWithDisplayName, int>::Iterator end = proFilesWithTestSets.end(); QHash<ProFileWithDisplayName, int>::ConstIterator it = proFilesWithTestSets.begin();
QHash<ProFileWithDisplayName, int>::ConstIterator end = proFilesWithTestSets.end();
for ( ; it != end; ++it) { for ( ; it != end; ++it) {
const ProFileWithDisplayName &key = it.key(); const ProFileWithDisplayName &key = it.key();
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value()); TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
@@ -309,6 +313,7 @@ QList<TestConfiguration *> TestTreeModel::getAllTestCases() const
tc->setProject(project); tc->setProject(project);
result << tc; result << tc;
} }
}
return result; return result;
} }
@@ -371,7 +376,7 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
// on and on and on... // on and on and on...
// TODO: do this later on for Auto Tests as well to support strange setups? or redo the model // TODO: do this later on for Auto Tests as well to support strange setups? or redo the model
QMap<QString, TestConfiguration *> foundProFiles; QHash<QString, TestConfiguration *> foundProFiles;
if (TestTreeItem *unnamed = unnamedQuickTests()) { if (TestTreeItem *unnamed = unnamedQuickTests()) {
for (int childRow = 0, ccount = unnamed->childCount(); childRow < ccount; ++ childRow) { for (int childRow = 0, ccount = unnamed->childCount(); childRow < ccount; ++ childRow) {
@@ -437,12 +442,17 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
} }
} }
foreach (TestConfiguration *config, foundProFiles.values()) { {
QHash<QString, TestConfiguration *>::ConstIterator it = foundProFiles.begin();
QHash<QString, TestConfiguration *>::ConstIterator end = foundProFiles.end();
for ( ; it != end; ++it) {
TestConfiguration *config = it.value();
if (!config->unnamedOnly()) if (!config->unnamedOnly())
result << config; result << config;
else else
delete config; delete config;
} }
}
// get selected Google Tests // get selected Google Tests
QHash<ProFileWithDisplayName, QStringList> proFilesWithCheckedTestSets; QHash<ProFileWithDisplayName, QStringList> proFilesWithCheckedTestSets;
@@ -465,8 +475,9 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
} }
} }
QHash<ProFileWithDisplayName, QStringList>::Iterator it = proFilesWithCheckedTestSets.begin(); {
QHash<ProFileWithDisplayName, QStringList>::Iterator end = proFilesWithCheckedTestSets.end(); QHash<ProFileWithDisplayName, QStringList>::ConstIterator it = proFilesWithCheckedTestSets.begin();
QHash<ProFileWithDisplayName, QStringList>::ConstIterator end = proFilesWithCheckedTestSets.end();
for ( ; it != end; ++it) { for ( ; it != end; ++it) {
const ProFileWithDisplayName &key = it.key(); const ProFileWithDisplayName &key = it.key();
TestConfiguration *tc = new TestConfiguration(QString(), it.value()); TestConfiguration *tc = new TestConfiguration(QString(), it.value());
@@ -476,6 +487,7 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
tc->setProject(project); tc->setProject(project);
result << tc; result << tc;
} }
}
return result; return result;
} }
@@ -649,9 +661,9 @@ void TestTreeModel::sweep()
#endif #endif
} }
QMap<QString, QString> TestTreeModel::testCaseNamesForFiles(QStringList files) QHash<QString, QString> TestTreeModel::testCaseNamesForFiles(QStringList files)
{ {
QMap<QString, QString> result; QHash<QString, QString> result;
if (!m_autoTestRootItem) if (!m_autoTestRootItem)
return result; return result;

View File

@@ -81,7 +81,7 @@ public:
void markAllForRemoval(); void markAllForRemoval();
void markForRemoval(const QString &filePath); void markForRemoval(const QString &filePath);
void sweep(); void sweep();
QMap<QString, QString> testCaseNamesForFiles(QStringList files); QHash<QString, QString> testCaseNamesForFiles(QStringList files);
signals: signals:
void testTreeModelChanged(); void testTreeModelChanged();