Fix the benchmark for QList::removeAll()
The benchmark was making assumptions about number of constructor/assignment operator calls, which are not valid in Qt 6, after the implementation of QList has changed. Considering that we already check number of constructions, copy constructions, etc., in tst_qlist.cpp, remove the checks from the benchmark. As a driveby, fix the following warning: "warning: parameter 'i' shadows member inherited from type 'MyBase'" Pick-to: 6.2 Fixes: QTBUG-95096 Change-Id: Ida68fa5803641c8fa84f8309c0093986ed4c0a2b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
This commit is contained in:
parent
b886a7ca65
commit
0fbeac0115
@ -35,88 +35,42 @@ static const int N = 1000;
|
|||||||
|
|
||||||
struct MyBase
|
struct MyBase
|
||||||
{
|
{
|
||||||
MyBase(int i_)
|
MyBase(int i_) : i(i_) { }
|
||||||
: isCopy(false)
|
|
||||||
{
|
|
||||||
++liveCount;
|
|
||||||
|
|
||||||
i = i_;
|
MyBase(const MyBase &other) : i(other.i) { }
|
||||||
}
|
|
||||||
|
|
||||||
MyBase(const MyBase &other)
|
|
||||||
: isCopy(true)
|
|
||||||
{
|
|
||||||
if (isCopy)
|
|
||||||
++copyCount;
|
|
||||||
++liveCount;
|
|
||||||
|
|
||||||
i = other.i;
|
|
||||||
}
|
|
||||||
|
|
||||||
MyBase &operator=(const MyBase &other)
|
MyBase &operator=(const MyBase &other)
|
||||||
{
|
{
|
||||||
if (!isCopy) {
|
|
||||||
isCopy = true;
|
|
||||||
++copyCount;
|
|
||||||
} else {
|
|
||||||
++errorCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = other.i;
|
i = other.i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~MyBase()
|
|
||||||
{
|
|
||||||
if (isCopy) {
|
|
||||||
if (!copyCount)
|
|
||||||
++errorCount;
|
|
||||||
else
|
|
||||||
--copyCount;
|
|
||||||
}
|
|
||||||
if (!liveCount)
|
|
||||||
++errorCount;
|
|
||||||
else
|
|
||||||
--liveCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const MyBase &other) const
|
bool operator==(const MyBase &other) const
|
||||||
{ return i == other.i; }
|
{ return i == other.i; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ushort i;
|
int i;
|
||||||
bool isCopy;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static int errorCount;
|
|
||||||
static int liveCount;
|
|
||||||
static int copyCount;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int MyBase::errorCount = 0;
|
|
||||||
int MyBase::liveCount = 0;
|
|
||||||
int MyBase::copyCount = 0;
|
|
||||||
|
|
||||||
struct MyPrimitive : public MyBase
|
struct MyPrimitive : public MyBase
|
||||||
{
|
{
|
||||||
MyPrimitive(int i = -1) : MyBase(i)
|
MyPrimitive(int i_ = -1) : MyBase(i_) { }
|
||||||
{ ++errorCount; }
|
MyPrimitive(const MyPrimitive &other) : MyBase(other) { }
|
||||||
MyPrimitive(const MyPrimitive &other) : MyBase(other)
|
|
||||||
{ ++errorCount; }
|
|
||||||
MyPrimitive &operator=(const MyPrimitive &other)
|
MyPrimitive &operator=(const MyPrimitive &other)
|
||||||
{ ++errorCount; MyBase::operator=(other); return *this; }
|
{
|
||||||
~MyPrimitive()
|
MyBase::operator=(other);
|
||||||
{ ++errorCount; }
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MyMovable : public MyBase
|
struct MyMovable : public MyBase
|
||||||
{
|
{
|
||||||
MyMovable(int i = -1) : MyBase(i) {}
|
MyMovable(int i_ = -1) : MyBase(i_) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MyComplex : public MyBase
|
struct MyComplex : public MyBase
|
||||||
{
|
{
|
||||||
MyComplex(int i = -1) : MyBase(i) {}
|
MyComplex(int i_ = -1) : MyBase(i_) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -283,33 +237,20 @@ private:
|
|||||||
template <class T>
|
template <class T>
|
||||||
void tst_QList::removeAll_impl() const
|
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(QList<int>, i10);
|
||||||
QFETCH(int, itemsToRemove);
|
QFETCH(int, itemsToRemove);
|
||||||
|
|
||||||
constexpr int valueToRemove = 5;
|
constexpr int valueToRemove = 5;
|
||||||
constexpr bool isComplex = QTypeInfo<T>::isComplex;
|
|
||||||
|
|
||||||
MyBase::errorCount = 0;
|
|
||||||
MyBase::liveCount = 0;
|
|
||||||
MyBase::copyCount = 0;
|
|
||||||
{
|
|
||||||
QList<T> list;
|
QList<T> list;
|
||||||
QCOMPARE(MyBase::liveCount, 0);
|
|
||||||
QCOMPARE(MyBase::copyCount, 0);
|
|
||||||
|
|
||||||
for (int i = 0; i < 10 * N; ++i) {
|
for (int i = 0; i < 10 * N; ++i) {
|
||||||
T t(i10.at(i % 10));
|
T t(i10.at(i % 10));
|
||||||
list.append(t);
|
list.append(t);
|
||||||
}
|
}
|
||||||
QCOMPARE(MyBase::liveCount, isComplex ? list.size() : 0);
|
|
||||||
QCOMPARE(MyBase::copyCount, isComplex ? list.size() : 0);
|
|
||||||
|
|
||||||
T t(valueToRemove);
|
T t(valueToRemove);
|
||||||
QCOMPARE(MyBase::liveCount, isComplex ? list.size() + 1 : 1);
|
|
||||||
QCOMPARE(MyBase::copyCount, isComplex ? list.size() : 0);
|
|
||||||
|
|
||||||
int removedCount = 0; // make compiler happy by setting to 0
|
qsizetype removedCount = 0; // make compiler happy by setting to 0
|
||||||
QList<T> l;
|
QList<T> l;
|
||||||
|
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
@ -319,14 +260,6 @@ void tst_QList::removeAll_impl() const
|
|||||||
QCOMPARE(removedCount, itemsToRemove * N);
|
QCOMPARE(removedCount, itemsToRemove * N);
|
||||||
QCOMPARE(l.size() + removedCount, list.size());
|
QCOMPARE(l.size() + removedCount, list.size());
|
||||||
QVERIFY(!l.contains(valueToRemove));
|
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);
|
|
||||||
}
|
|
||||||
if (isComplex)
|
|
||||||
QCOMPARE(MyBase::errorCount, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QList::removeAll_primitive_data()
|
void tst_QList::removeAll_primitive_data()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user