From 19f522c74aa756401de59ceb202b1338660d2be9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 9 Jul 2021 11:31:40 +0200 Subject: QList benchmark: inline the removAll tests to match most others It may be the hobgoblin of little minds, but consistency makes code easier to read. Turn the implementation test into a method of the class, like all the others, and rename it to match the common pattern. In the process, eliminate the data-column that was constant, use simpler expressions for the lists whose entries are all the same and Split some long lines. The test still fails, as it did previously. Change-Id: Ic2d6db1edc0bbafad91cd732babcbc129c430b8f Reviewed-by: Andrei Golubev --- tests/benchmarks/corelib/tools/qlist/main.cpp | 76 ++++++++------------------- 1 file changed, 23 insertions(+), 53 deletions(-) (limited to 'tests/benchmarks/corelib/tools/qlist/main.cpp') diff --git a/tests/benchmarks/corelib/tools/qlist/main.cpp b/tests/benchmarks/corelib/tools/qlist/main.cpp index b65d02b750..cede305c4f 100644 --- a/tests/benchmarks/corelib/tools/qlist/main.cpp +++ b/tests/benchmarks/corelib/tools/qlist/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -134,11 +134,11 @@ class tst_QList: public QObject private Q_SLOTS: void removeAll_primitive_data(); - void removeAll_primitive(); - void removeAll_movable_data(); - void removeAll_movable(); - void removeAll_complex_data(); - void removeAll_complex(); + void removeAll_primitive() { removeAll_impl(); } + void removeAll_movable_data() { removeAll_primitive_data(); } + void removeAll_movable() { removeAll_impl(); } + void removeAll_complex_data() { removeAll_primitive_data(); } + void removeAll_complex() { removeAll_impl(); } // append 1 element: void appendOne_int_data() const { commonBenchmark_data(); } @@ -248,6 +248,9 @@ private Q_SLOTS: void removeFirstSpecial_QString() const { removeFirstSpecial_impl(); } private: + template + void removeAll_impl() const; + template void commonBenchmark_data() const; @@ -277,9 +280,13 @@ private: }; template -void removeAll_test(const QList &i10, ushort valueToRemove, int itemsToRemove) +void tst_QList::removeAll_impl() const { - bool isComplex = QTypeInfo::isComplex; + QFETCH(QList, i10); + QFETCH(int, itemsToRemove); + + constexpr int valueToRemove = 5; + constexpr bool isComplex = QTypeInfo::isComplex; MyBase::errorCount = 0; MyBase::liveCount = 0; @@ -311,63 +318,26 @@ void removeAll_test(const QList &i10, ushort valueToRemove, int itemsToRemo QCOMPARE(l.size() + removedCount, list.size()); QVERIFY(!l.contains(valueToRemove)); - QCOMPARE(MyBase::liveCount, isComplex ? l.isDetached() ? list.size() + l.size() + 1 : list.size() + 1 : 1); - QCOMPARE(MyBase::copyCount, isComplex ? l.isDetached() ? list.size() + l.size() : list.size() : 0); + QCOMPARE(MyBase::liveCount, + isComplex ? l.isDetached() ? list.size() + l.size() + 1 : list.size() + 1 : 1); + QCOMPARE(MyBase::copyCount, + isComplex ? l.isDetached() ? list.size() + l.size() : list.size() : 0); } if (isComplex) QCOMPARE(MyBase::errorCount, 0); } - void tst_QList::removeAll_primitive_data() { qRegisterMetaType >(); QTest::addColumn >("i10"); - QTest::addColumn("valueToRemove"); QTest::addColumn("itemsToRemove"); - QTest::newRow("0%") << (QList() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0) << 5 << 0; - QTest::newRow("10%") << (QList() << 0 << 0 << 0 << 0 << 5 << 0 << 0 << 0 << 0 << 0) << 5 << 1; - QTest::newRow("90%") << (QList() << 5 << 5 << 5 << 5 << 0 << 5 << 5 << 5 << 5 << 5) << 5 << 9; - QTest::newRow("100%") << (QList() << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5) << 5 << 10; -} - -void tst_QList::removeAll_primitive() -{ - QFETCH(QList, i10); - QFETCH(int, valueToRemove); - QFETCH(int, itemsToRemove); - - removeAll_test(i10, valueToRemove, itemsToRemove); -} - -void tst_QList::removeAll_movable_data() -{ - removeAll_primitive_data(); -} - -void tst_QList::removeAll_movable() -{ - QFETCH(QList, i10); - QFETCH(int, valueToRemove); - QFETCH(int, itemsToRemove); - - removeAll_test(i10, valueToRemove, itemsToRemove); -} - -void tst_QList::removeAll_complex_data() -{ - removeAll_primitive_data(); -} - -void tst_QList::removeAll_complex() -{ - QFETCH(QList, i10); - QFETCH(int, valueToRemove); - QFETCH(int, itemsToRemove); - - removeAll_test(i10, valueToRemove, itemsToRemove); + QTest::newRow("0%") << QList(10, 0) << 0; + QTest::newRow("10%") << (QList() << 0 << 0 << 0 << 0 << 5 << 0 << 0 << 0 << 0 << 0) << 1; + QTest::newRow("90%") << (QList() << 5 << 5 << 5 << 5 << 0 << 5 << 5 << 5 << 5 << 5) << 9; + QTest::newRow("100%") << QList(10, 5) << 10; } template -- cgit v1.2.3