Skip to content
Snippets Groups Projects
Commit a31ce64b authored by hjk's avatar hjk
Browse files

qstringbuilder: also accept QStringRef

parent 295a0102
No related branches found
No related tags found
No related merge requests found
......@@ -137,6 +137,7 @@ inline int qStringBuilderSize(const QLatin1Char) { return 1; }
inline int qStringBuilderSize(const QLatin1String a) { return qstrlen(a.latin1()); }
template <typename A>
inline void qStringBuilderAppend(const A a, QChar *&out) { a.appendTo(out); }
......@@ -150,6 +151,14 @@ inline void qStringBuilderAppend(QLatin1String a, QChar *&out)
*out++ = QLatin1Char(*s++);
}
inline void qStringBuilderAppend(QStringRef a, QChar *&out)
{
const int n = a.size();
memcpy(out, (char*)a.constData(), sizeof(QChar) * n);
out += n;
}
template <typename A, typename B>
class QStringBuilderPair
......
......@@ -22,6 +22,7 @@ public:
: l1literal("some string literal"),
l1string("some string literal"),
string(l1string),
stringref(&string, 2, 10),
achar('c')
{}
......@@ -90,6 +91,18 @@ private slots:
}
void separator_2c() { SEP("2 string refs"); }
void b_2_stringref() {
QBENCHMARK { r = stringref % stringref; }
COMPARE(r, stringref.toString() + stringref.toString());
}
void s_2_stringref() {
QBENCHMARK { r = stringref.toString() + stringref.toString(); }
COMPARE(r, QString(stringref % stringref));
}
void separator_2b() { SEP("3 strings"); }
void b_3_string() {
......@@ -188,6 +201,7 @@ private:
const QLatin1Literal l1literal;
const QLatin1String l1string;
const QString string;
const QStringRef stringref;
const QLatin1Char achar;
QString r;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment