forked from qt-creator/qt-creator
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:
@@ -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) {
|
||||||
|
|||||||
@@ -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,12 +270,15 @@ 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) {
|
||||||
tc->setProject(project);
|
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
|
||||||
result << tc;
|
tc->setProFile(it.key());
|
||||||
|
tc->setProject(project);
|
||||||
|
result << tc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foundProFiles.clear();
|
foundProFiles.clear();
|
||||||
@@ -298,16 +301,18 @@ 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();
|
||||||
for ( ; it != end; ++it) {
|
QHash<ProFileWithDisplayName, int>::ConstIterator end = proFilesWithTestSets.end();
|
||||||
const ProFileWithDisplayName &key = it.key();
|
for ( ; it != end; ++it) {
|
||||||
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
|
const ProFileWithDisplayName &key = it.key();
|
||||||
tc->setTestType(TestTypeGTest);
|
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
|
||||||
tc->setProFile(key.proFile);
|
tc->setTestType(TestTypeGTest);
|
||||||
tc->setDisplayName(key.displayName);
|
tc->setProFile(key.proFile);
|
||||||
tc->setProject(project);
|
tc->setDisplayName(key.displayName);
|
||||||
result << tc;
|
tc->setProject(project);
|
||||||
|
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,11 +442,16 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (TestConfiguration *config, foundProFiles.values()) {
|
{
|
||||||
if (!config->unnamedOnly())
|
QHash<QString, TestConfiguration *>::ConstIterator it = foundProFiles.begin();
|
||||||
result << config;
|
QHash<QString, TestConfiguration *>::ConstIterator end = foundProFiles.end();
|
||||||
else
|
for ( ; it != end; ++it) {
|
||||||
delete config;
|
TestConfiguration *config = it.value();
|
||||||
|
if (!config->unnamedOnly())
|
||||||
|
result << config;
|
||||||
|
else
|
||||||
|
delete config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get selected Google Tests
|
// get selected Google Tests
|
||||||
@@ -465,16 +475,18 @@ 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();
|
||||||
for ( ; it != end; ++it) {
|
QHash<ProFileWithDisplayName, QStringList>::ConstIterator end = proFilesWithCheckedTestSets.end();
|
||||||
const ProFileWithDisplayName &key = it.key();
|
for ( ; it != end; ++it) {
|
||||||
TestConfiguration *tc = new TestConfiguration(QString(), it.value());
|
const ProFileWithDisplayName &key = it.key();
|
||||||
tc->setTestType(TestTypeGTest);
|
TestConfiguration *tc = new TestConfiguration(QString(), it.value());
|
||||||
tc->setProFile(key.proFile);
|
tc->setTestType(TestTypeGTest);
|
||||||
tc->setDisplayName(key.displayName);
|
tc->setProFile(key.proFile);
|
||||||
tc->setProject(project);
|
tc->setDisplayName(key.displayName);
|
||||||
result << tc;
|
tc->setProject(project);
|
||||||
|
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;
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user