QtTest: eradicate all Q_FOREACH loops

... by replacing them with C++11 ramge-for loops.

In one case, I took the liberty to remove a useless
if(isEmpty()) check around a for loop. Now that we
don't use Q_FOREACH anymore, we don't incur the copy
for empty containers anymore. Left the indention of
the loop level to avoid code churn.

Saves 1.8KiB in text size on optimized GCC 5.3 Linux
AMD64 builds.

Change-Id: I1b1fb34847f6a631f0d580fd5261c7f5fed8475c
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2016-01-25 12:23:56 +01:00
parent a7885c9756
commit be84480785
3 changed files with 7 additions and 9 deletions

View File

@ -115,13 +115,13 @@ QString QBenchmarkValgrindUtils::getNewestFileName()
Q_ASSERT(!base.isEmpty()); Q_ASSERT(!base.isEmpty());
nameFilters << QString::fromLatin1("%1.*").arg(base); nameFilters << QString::fromLatin1("%1.*").arg(base);
QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable); const QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable);
Q_ASSERT(!fiList.empty()); Q_ASSERT(!fiList.empty());
int hiSuffix = -1; int hiSuffix = -1;
QFileInfo lastFileInfo; QFileInfo lastFileInfo;
const QString pattern = QString::fromLatin1("%1.(\\d+)").arg(base); const QString pattern = QString::fromLatin1("%1.(\\d+)").arg(base);
QRegExp rx(pattern); QRegExp rx(pattern);
foreach (const QFileInfo &fileInfo, fiList) { for (const QFileInfo &fileInfo : fiList) {
const int index = rx.indexIn(fileInfo.fileName()); const int index = rx.indexIn(fileInfo.fileName());
Q_ASSERT(index == 0); Q_ASSERT(index == 0);
Q_UNUSED(index); Q_UNUSED(index);
@ -151,8 +151,8 @@ void QBenchmarkValgrindUtils::cleanup()
nameFilters nameFilters
<< base // overall summary << base // overall summary
<< QString::fromLatin1("%1.*").arg(base); // individual dumps << QString::fromLatin1("%1.*").arg(base); // individual dumps
QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable); const QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable);
foreach (const QFileInfo &fileInfo, fiList) { for (const QFileInfo &fileInfo : fiList) {
const bool removeOk = QFile::remove(fileInfo.fileName()); const bool removeOk = QFile::remove(fileInfo.fileName());
Q_ASSERT(removeOk); Q_ASSERT(removeOk);
Q_UNUSED(removeOk); Q_UNUSED(removeOk);

View File

@ -151,7 +151,7 @@ public:
return res; return res;
} }
static bool containsEvent(QAccessibleEvent *event) { static bool containsEvent(QAccessibleEvent *event) {
Q_FOREACH (const QAccessibleEvent *ev, eventList()) { for (const QAccessibleEvent *ev : qAsConst(eventList())) {
if (*ev == *event) if (*ev == *event)
return true; return true;
} }
@ -285,7 +285,7 @@ private:
QDebug str = QDebug(&rc).nospace(); QDebug str = QDebug(&rc).nospace();
str << "Event " << *needle str << "Event " << *needle
<< " not found at head of event list of size " << haystack.size() << " :"; << " not found at head of event list of size " << haystack.size() << " :";
Q_FOREACH (const QAccessibleEvent *e, haystack) for (const QAccessibleEvent *e : haystack)
str << ' ' << *e; str << ' ' << *e;
return rc; return rc;
} }

View File

@ -1694,8 +1694,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
handler.reset(new FatalSignalHandler); handler.reset(new FatalSignalHandler);
#endif #endif
TestMethods::MetaMethods commandLineMethods; TestMethods::MetaMethods commandLineMethods;
if (!QTest::testFunctions.isEmpty()) { for (const QString &tf : qAsConst(QTest::testFunctions)) {
foreach (const QString &tf, QTest::testFunctions) {
const QByteArray tfB = tf.toLatin1(); const QByteArray tfB = tf.toLatin1();
const QByteArray signature = tfB + QByteArrayLiteral("()"); const QByteArray signature = tfB + QByteArrayLiteral("()");
QMetaMethod m = TestMethods::findMethod(testObject, signature.constData()); QMetaMethod m = TestMethods::findMethod(testObject, signature.constData());
@ -1706,7 +1705,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
exit(1); exit(1);
} }
commandLineMethods.push_back(m); commandLineMethods.push_back(m);
}
} }
TestMethods test(testObject, commandLineMethods); TestMethods test(testObject, commandLineMethods);
test.invokeTests(testObject); test.invokeTests(testObject);