QTestLib: Speed up QCOMPARE for QString
Add overloads for qCompare() for QStringView making use of the fast
formatting helper introduced by 94aa350621
for int.
Speeds up the bug report example by a factor of 3..4.
Task-number: QTBUG-38890
Change-Id: Icc706618b2f1d23b37d354a04d4e1d1cc4b5aee3
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
10845315b7
commit
f23f9ba041
@ -2587,6 +2587,57 @@ bool QTest::qCompare(unsigned t1, unsigned t2, const char *actual, const char *e
|
||||
t1, t2, actual, expected, file, line);
|
||||
}
|
||||
|
||||
/*! \fn bool QTest::qCompare(QStringView t1, QStringView t2, const char *actual, const char *expected, const char *file, int line)
|
||||
\internal
|
||||
\since 5.14
|
||||
*/
|
||||
bool QTest::qCompare(QStringView t1, QStringView t2, const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return QTestResult::compare(t1 == t2,
|
||||
"Compared values are not the same",
|
||||
t1, t2, actual, expected, file, line);
|
||||
}
|
||||
|
||||
/*! \fn bool QTest::qCompare(QStringView t1, const QLatin1String &t2, const char *actual, const char *expected, const char *file, int line)
|
||||
\internal
|
||||
\since 5.14
|
||||
*/
|
||||
bool QTest::qCompare(QStringView t1, const QLatin1String &t2, const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return QTestResult::compare(t1 == t2,
|
||||
"Compared values are not the same",
|
||||
t1, t2, actual, expected, file, line);
|
||||
}
|
||||
|
||||
/*! \fn bool QTest::qCompare(const QLatin1String &t1, QStringView t2, const char *actual, const char *expected, const char *file, int line)
|
||||
\internal
|
||||
\since 5.14
|
||||
*/
|
||||
bool QTest::qCompare(const QLatin1String &t1, QStringView t2, const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return QTestResult::compare(t1 == t2,
|
||||
"Compared values are not the same",
|
||||
t1, t2, actual, expected, file, line);
|
||||
}
|
||||
|
||||
/*! \fn bool QTest::qCompare(const QString &t1, const QString &t2, const char *actual, const char *expected, const char *file, int line)
|
||||
\internal
|
||||
\since 5.14
|
||||
*/
|
||||
|
||||
/*! \fn bool QTest::qCompare(const QString &t1, const QLatin1String &t2, const char *actual, const char *expected, const char *file, int line)
|
||||
\internal
|
||||
\since 5.14
|
||||
*/
|
||||
|
||||
/*! \fn bool QTest::qCompare(const QLatin1String &t1, const QString &t2, const char *actual, const char *expected, const char *file, int line)
|
||||
\internal
|
||||
\since 5.14
|
||||
*/
|
||||
|
||||
/*! \fn bool QTest::qCompare(const double &t1, const float &t2, const char *actual, const char *expected, const char *file, int line)
|
||||
\internal
|
||||
*/
|
||||
|
@ -369,6 +369,34 @@ namespace QTest
|
||||
Q_TESTLIB_EXPORT bool qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected,
|
||||
const char *file, int line);
|
||||
|
||||
Q_TESTLIB_EXPORT bool qCompare(QStringView t1, QStringView t2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line);
|
||||
Q_TESTLIB_EXPORT bool qCompare(QStringView t1, const QLatin1String &t2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line);
|
||||
Q_TESTLIB_EXPORT bool qCompare(const QLatin1String &t1, QStringView t2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line);
|
||||
inline bool qCompare(const QString &t1, const QString &t2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return qCompare(QStringView(t1), QStringView(t2), actual, expected, file, line);
|
||||
}
|
||||
inline bool qCompare(const QString &t1, const QLatin1String &t2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return qCompare(QStringView(t1), t2, actual, expected, file, line);
|
||||
}
|
||||
inline bool qCompare(const QLatin1String &t1, const QString &t2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return qCompare(t1, QStringView(t2), actual, expected, file, line);
|
||||
}
|
||||
|
||||
inline bool compare_ptr_helper(const volatile void *t1, const volatile void *t2, const char *actual,
|
||||
const char *expected, const char *file, int line)
|
||||
{
|
||||
|
@ -39,8 +39,10 @@
|
||||
|
||||
#include <QtTest/private/qtestresult_p.h>
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/qstringview.h>
|
||||
|
||||
#include <QtTest/private/qtestlog_p.h>
|
||||
#include <QtTest/qtest.h> // toString() specializations for QStringView
|
||||
#include <QtTest/qtestdata.h>
|
||||
#include <QtTest/qtestcase.h>
|
||||
#include <QtTest/qtestassert.h>
|
||||
@ -389,6 +391,30 @@ bool QTestResult::compare(bool success, const char *failureMsg,
|
||||
return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
|
||||
}
|
||||
|
||||
bool QTestResult::compare(bool success, const char *failureMsg,
|
||||
QStringView val1, QStringView val2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
|
||||
}
|
||||
|
||||
bool QTestResult::compare(bool success, const char *failureMsg,
|
||||
QStringView val1, const QLatin1String &val2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
|
||||
}
|
||||
|
||||
bool QTestResult::compare(bool success, const char *failureMsg,
|
||||
const QLatin1String & val1, QStringView val2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
{
|
||||
return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
|
||||
}
|
||||
|
||||
void QTestResult::addFailure(const char *message, const char *file, int line)
|
||||
{
|
||||
clearExpectFail();
|
||||
|
@ -55,6 +55,9 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QLatin1String;
|
||||
class QStringView;
|
||||
|
||||
class QTestResultPrivate;
|
||||
class QTestData;
|
||||
|
||||
@ -95,6 +98,18 @@ public:
|
||||
unsigned val1, unsigned val2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line);
|
||||
static bool compare(bool success, const char *failureMsg,
|
||||
QStringView val1, QStringView val2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line);
|
||||
static bool compare(bool success, const char *failureMsg,
|
||||
const QLatin1String &val1, QStringView val2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line);
|
||||
static bool compare(bool success, const char *failureMsg,
|
||||
QStringView val1, const QLatin1String &val2,
|
||||
const char *actual, const char *expected,
|
||||
const char *file, int line);
|
||||
static void setCurrentGlobalTestData(QTestData *data);
|
||||
static void setCurrentTestData(QTestData *data);
|
||||
static void setCurrentTestFunction(const char *func);
|
||||
|
Loading…
Reference in New Issue
Block a user