From d201c90c1ca19f9831a6a6590fd9dbaaef103bb0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 14 Jun 2021 16:31:56 +0200 Subject: 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 Reviewed-by: Edward Welbourne --- src/testlib/qtestcase.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/testlib') 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; - 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(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); } -- cgit v1.2.3