Commit 4774ba14 authored by hjk's avatar hjk
Browse files

qstringbuilder: add a new benchmark using QString::arg

parent dc0bc586
......@@ -46,6 +46,13 @@
#include <string.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Core)
// Using this relies on changing the QString::QString(QChar *, int)
// constructor to allocated an unitialized string of the given size.
//#define USE_CHANGED_QSTRING 1
......@@ -89,7 +96,7 @@ template <typename A>
class QStringBuilder : public A
{
public:
QStringBuilder(A a_) : A(a_) {}
QStringBuilder(const A &a_) : A(a_) {}
operator QString() const
{
......@@ -164,7 +171,7 @@ template <typename A, typename B>
class QStringBuilderPair
{
public:
QStringBuilderPair(A a_, B b_) : a(a_), b(b_) {}
QStringBuilderPair(const A &a_, const B &b_) : a(a_), b(b_) {}
inline int size() const
{
......@@ -178,8 +185,8 @@ public:
}
private:
A a;
B b;
const A a;
const B b;
};
......@@ -216,5 +223,8 @@ operator%(const QString &a, const QString &b)
QStringBuilder<QString> > (a, b);
}
QT_END_NAMESPACE
QT_END_HEADER
#endif // QSTRINGBUILDER_H
......@@ -21,6 +21,7 @@ public:
tst_qstringbuilder()
: l1literal("some string literal"),
l1string("some string literal"),
ba("some string literal"),
string(l1string),
stringref(&string, 2, 10),
achar('c')
......@@ -197,9 +198,29 @@ private slots:
COMPARE(r, QString(achar % string % achar));
}
void separator_8() { SEP("string.arg"); }
void b_string_arg() {
const QString pattern = l1string + "%1" + l1string;
QBENCHMARK { r = l1literal % string % l1literal; }
COMPARE(r, l1string + string + l1string);
}
void s_string_arg() {
const QString pattern = l1string + "%1" + l1string;
QBENCHMARK { r = pattern.arg(string); }
COMPARE(r, l1string + string + l1string);
}
void s_bytearray_arg() {
QByteArray result;
QBENCHMARK { result = ba + ba + ba; }
}
private:
const QLatin1Literal l1literal;
const QLatin1String l1string;
const QByteArray ba;
const QString string;
const QStringRef stringref;
const QLatin1Char achar;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment