Make adding new rows to QTestTable more efficient
Added QDuplicateTracker to keep track of used tags, rather than looping through QTestTablePrivate::dataList for every added tag. Removed method `hasRow`, instead calling `QDuplicateTracker::hasSeen` directly in `newData`. Task-number: QTBUG-118619 Change-Id: Idaab70d8c94227f75620924e0f1ead477f93b27a Reviewed-by: Marc Mutz <marc.mutz@qt.io> (cherry picked from commit 8a23e3aa323443d2ea958b1213b00031e5b13aed) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2dc02a2aeb
commit
f7f5477ec5
@ -5,6 +5,7 @@
|
||||
#include <QtTest/qtestdata.h>
|
||||
#include <QtTest/qtestassert.h>
|
||||
|
||||
#include <QtCore/private/qduplicatetracker_p.h>
|
||||
#include <QtCore/qmetaobject.h>
|
||||
|
||||
#include <string.h>
|
||||
@ -35,9 +36,11 @@ public:
|
||||
using DataList = std::vector<QTestData *>;
|
||||
DataList dataList;
|
||||
|
||||
using TagSet = QDuplicateTracker<std::string>;
|
||||
TagSet tagSet;
|
||||
|
||||
void addColumn(int elemType, const char *elemName) { elementList.push_back(Element(elemName, elemType)); }
|
||||
void addRow(QTestData *data) { dataList.push_back(data); }
|
||||
bool hasRow(const char *name) const;
|
||||
|
||||
static QTestTable *currentTestTable;
|
||||
static QTestTable *gTable;
|
||||
@ -73,7 +76,8 @@ bool QTestTable::isEmpty() const
|
||||
|
||||
QTestData *QTestTable::newData(const char *tag)
|
||||
{
|
||||
if (d->hasRow(tag))
|
||||
QTEST_ASSERT(tag);
|
||||
if (d->tagSet.hasSeen(tag))
|
||||
qWarning("Duplicate data tag \"%s\" - please rename.", tag);
|
||||
|
||||
QTestData *dt = new QTestData(tag, this);
|
||||
@ -123,12 +127,6 @@ private:
|
||||
const char *m_needle;
|
||||
};
|
||||
|
||||
bool QTestTablePrivate::hasRow(const char *rowName) const
|
||||
{
|
||||
QTEST_ASSERT(rowName);
|
||||
return std::find_if(dataList.begin(), dataList.end(), NamePredicate(rowName)) != dataList.end();
|
||||
}
|
||||
|
||||
int QTestTable::indexOf(const char *elementName) const
|
||||
{
|
||||
QTEST_ASSERT(elementName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user