summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcoreelement_p.h
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-09-08 16:34:19 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-09-10 22:19:45 +0200
commitb8191f41c65a908d0529d235b0200e6de99c34fb (patch)
tree59d750687ba5896cd4638780bb32193a5f563961 /src/testlib/qtestcoreelement_p.h
parent4e0082a9cacfdfd0c43e6105274bc0d41dd18801 (diff)
testlib: Replace custom QTestCoreList with std::vector
The custom linked list implementation was implemented using recursion, and as a result didn't handle long lists of test cases, exhausting the stack on e.g. Windows where the default stack is only 1MB. This was the case with e.g. the tst_QChar test that produces 20K test cases. Replacing with a std::vector should do nicely for our use-case. No attempt has been made at further reducing the complexity of QTestElement/QTestCoreElement/QTestElementAttribute. Pick-to: 6.2 Change-Id: Ie295f7cf937ec6abdc4606b6120818551ad285c7 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/testlib/qtestcoreelement_p.h')
-rw-r--r--src/testlib/qtestcoreelement_p.h26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/testlib/qtestcoreelement_p.h b/src/testlib/qtestcoreelement_p.h
index 362a503126..a6a09aab52 100644
--- a/src/testlib/qtestcoreelement_p.h
+++ b/src/testlib/qtestcoreelement_p.h
@@ -51,21 +51,23 @@
// We mean it.
//
-#include <QtTest/private/qtestcorelist_p.h>
+#include <QtTest/qttestglobal.h>
#include <QtTest/private/qtestelementattribute_p.h>
+#include <vector>
+
QT_BEGIN_NAMESPACE
template <class ElementType>
-class QTestCoreElement: public QTestCoreList<ElementType>
+class QTestCoreElement
{
public:
QTestCoreElement( int type = -1 );
virtual ~QTestCoreElement();
void addAttribute(const QTest::AttributeIndex index, const char *value);
- QTestElementAttribute *attributes() const;
+ const std::vector<QTestElementAttribute*> &attributes() const;
const char *attributeValue(QTest::AttributeIndex index) const;
const char *attributeName(QTest::AttributeIndex index) const;
const QTestElementAttribute *attribute(QTest::AttributeIndex index) const;
@@ -74,7 +76,7 @@ class QTestCoreElement: public QTestCoreList<ElementType>
QTest::LogElementType elementType() const;
private:
- QTestElementAttribute *listOfAttributes = nullptr;
+ std::vector<QTestElementAttribute*> listOfAttributes;
QTest::LogElementType type;
};
@@ -87,7 +89,8 @@ QTestCoreElement<ElementType>::QTestCoreElement(int t)
template<class ElementType>
QTestCoreElement<ElementType>::~QTestCoreElement()
{
- delete listOfAttributes;
+ for (auto *attribute : listOfAttributes)
+ delete attribute;
}
template <class ElementType>
@@ -98,11 +101,11 @@ void QTestCoreElement<ElementType>::addAttribute(const QTest::AttributeIndex att
QTestElementAttribute *testAttribute = new QTestElementAttribute;
testAttribute->setPair(attributeIndex, value);
- testAttribute->addToList(&listOfAttributes);
+ listOfAttributes.push_back(testAttribute);
}
template <class ElementType>
-QTestElementAttribute *QTestCoreElement<ElementType>::attributes() const
+const std::vector<QTestElementAttribute*> &QTestCoreElement<ElementType>::attributes() const
{
return listOfAttributes;
}
@@ -159,12 +162,9 @@ QTest::LogElementType QTestCoreElement<ElementType>::elementType() const
template <class ElementType>
const QTestElementAttribute *QTestCoreElement<ElementType>::attribute(QTest::AttributeIndex index) const
{
- QTestElementAttribute *iterator = listOfAttributes;
- while (iterator) {
- if (iterator->index() == index)
- return iterator;
-
- iterator = iterator->nextElement();
+ for (auto *attribute : listOfAttributes) {
+ if (attribute->index() == index)
+ return attribute;
}
return nullptr;