diff options
Diffstat (limited to 'tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp')
-rw-r--r-- | tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp | 146 |
1 files changed, 27 insertions, 119 deletions
diff --git a/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp b/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp index 9d6126ca7b..24691d1f71 100644 --- a/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp +++ b/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QList> #include <QTest> @@ -35,88 +10,42 @@ static const int N = 1000; struct MyBase { - MyBase(int i_) - : isCopy(false) - { - ++liveCount; - - i = i_; - } + MyBase(int i_) : i(i_) { } - MyBase(const MyBase &other) - : isCopy(true) - { - if (isCopy) - ++copyCount; - ++liveCount; - - i = other.i; - } + MyBase(const MyBase &other) : i(other.i) { } MyBase &operator=(const MyBase &other) { - if (!isCopy) { - isCopy = true; - ++copyCount; - } else { - ++errorCount; - } - i = other.i; return *this; } - ~MyBase() - { - if (isCopy) { - if (!copyCount) - ++errorCount; - else - --copyCount; - } - if (!liveCount) - ++errorCount; - else - --liveCount; - } - bool operator==(const MyBase &other) const { return i == other.i; } protected: - ushort i; - bool isCopy; - -public: - static int errorCount; - static int liveCount; - static int copyCount; + int i; }; -int MyBase::errorCount = 0; -int MyBase::liveCount = 0; -int MyBase::copyCount = 0; - struct MyPrimitive : public MyBase { - MyPrimitive(int i = -1) : MyBase(i) - { ++errorCount; } - MyPrimitive(const MyPrimitive &other) : MyBase(other) - { ++errorCount; } + MyPrimitive(int i_ = -1) : MyBase(i_) { } + MyPrimitive(const MyPrimitive &other) : MyBase(other) { } MyPrimitive &operator=(const MyPrimitive &other) - { ++errorCount; MyBase::operator=(other); return *this; } - ~MyPrimitive() - { ++errorCount; } + { + MyBase::operator=(other); + return *this; + } }; struct MyMovable : public MyBase { - MyMovable(int i = -1) : MyBase(i) {} + MyMovable(int i_ = -1) : MyBase(i_) {} }; struct MyComplex : public MyBase { - MyComplex(int i = -1) : MyBase(i) {} + MyComplex(int i_ = -1) : MyBase(i_) {} }; QT_BEGIN_NAMESPACE @@ -283,50 +212,29 @@ private: template <class T> void tst_QList::removeAll_impl() const { - QSKIP("QTBUG-95096: known to be broken (for some test-cases) since Qt 6.0"); QFETCH(QList<int>, i10); QFETCH(int, itemsToRemove); constexpr int valueToRemove = 5; - constexpr bool isComplex = QTypeInfo<T>::isComplex; - MyBase::errorCount = 0; - MyBase::liveCount = 0; - MyBase::copyCount = 0; - { - QList<T> list; - QCOMPARE(MyBase::liveCount, 0); - QCOMPARE(MyBase::copyCount, 0); - - for (int i = 0; i < 10 * N; ++i) { - T t(i10.at(i % 10)); - list.append(t); - } - QCOMPARE(MyBase::liveCount, isComplex ? list.size() : 0); - QCOMPARE(MyBase::copyCount, isComplex ? list.size() : 0); + QList<T> list; + for (int i = 0; i < 10 * N; ++i) { + T t(i10.at(i % 10)); + list.append(t); + } - T t(valueToRemove); - QCOMPARE(MyBase::liveCount, isComplex ? list.size() + 1 : 1); - QCOMPARE(MyBase::copyCount, isComplex ? list.size() : 0); + T t(valueToRemove); - int removedCount = 0; // make compiler happy by setting to 0 - QList<T> l; + qsizetype removedCount = 0; // make compiler happy by setting to 0 + QList<T> l; - QBENCHMARK { - l = list; - removedCount = l.removeAll(t); - } - QCOMPARE(removedCount, itemsToRemove * N); - 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); + QBENCHMARK { + l = list; + removedCount = l.removeAll(t); } - if (isComplex) - QCOMPARE(MyBase::errorCount, 0); + QCOMPARE(removedCount, itemsToRemove * N); + QCOMPARE(l.size() + removedCount, list.size()); + QVERIFY(!l.contains(valueToRemove)); } void tst_QList::removeAll_primitive_data() |