summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-06-14 16:31:56 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-06-22 15:26:31 +0200
commitd201c90c1ca19f9831a6a6590fd9dbaaef103bb0 (patch)
treee47f968924879554aa5f2306cf011ac5b69eb7e7 /src/testlib/qtestcase.cpp
parentf522cfc9b991402a8dbfc18c6e65b01da09298e8 (diff)
QtTest: de-pessimise TestMethods::MetaMethods handling
MetaMethods is a std::vector, so we should avoid copying it. Add strategic std::move()s and pass to the TestFunctions ctor by value, not cref. Change-Id: Iaa2879ae427b9603a7abaab0e3015556d9c247fc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index eca5bbb033..47f75fcc5b 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -310,7 +310,7 @@ public:
using MetaMethods = std::vector<QMetaMethod>;
- explicit TestMethods(const QObject *o, const MetaMethods &m = MetaMethods());
+ explicit TestMethods(const QObject *o, MetaMethods m = {});
void invokeTests(QObject *testObject) const;
@@ -329,15 +329,15 @@ private:
MetaMethods m_methods;
};
-TestMethods::TestMethods(const QObject *o, const MetaMethods &m)
+TestMethods::TestMethods(const QObject *o, MetaMethods m)
: m_initTestCaseMethod(TestMethods::findMethod(o, "initTestCase()"))
, m_initTestCaseDataMethod(TestMethods::findMethod(o, "initTestCase_data()"))
, m_cleanupTestCaseMethod(TestMethods::findMethod(o, "cleanupTestCase()"))
, m_initMethod(TestMethods::findMethod(o, "init()"))
, m_cleanupMethod(TestMethods::findMethod(o, "cleanup()"))
- , m_methods(m)
+ , m_methods(std::move(m))
{
- if (m.empty()) {
+ if (m_methods.empty()) {
const QMetaObject *metaObject = o->metaObject();
const int count = metaObject->methodCount();
m_methods.reserve(count);
@@ -1935,6 +1935,7 @@ int QTest::qRun()
handler.reset(new FatalSignalHandler);
TestMethods::MetaMethods commandLineMethods;
+ commandLineMethods.reserve(static_cast<size_t>(QTest::testFunctions.size()));
for (const QString &tf : qAsConst(QTest::testFunctions)) {
const QByteArray tfB = tf.toLatin1();
const QByteArray signature = tfB + QByteArrayLiteral("()");
@@ -1947,7 +1948,7 @@ int QTest::qRun()
}
commandLineMethods.push_back(m);
}
- TestMethods test(currentTestObject, commandLineMethods);
+ TestMethods test(currentTestObject, std::move(commandLineMethods));
test.invokeTests(currentTestObject);
}