Commit f4ba8f1d authored by hjk's avatar hjk
Browse files

qstringbuilder: more logic optimizations

Drop original QStringBuilder class, rename QStringBuilderPair to
QStringBuilder. Put everything except the QLatin1Literal class and
the global operator%() in a private namespace.
parent 0c134439
......@@ -87,17 +87,6 @@ private:
};
template <typename A, typename B>
class QStringBuilderPair
{
public:
QStringBuilderPair(const A &a_, const B &b_) : a(a_), b(b_) {}
const A &a;
const B &b;
};
namespace Qt {
inline int qStringBuilderSize(const char) { return 1; }
......@@ -112,12 +101,10 @@ inline int qStringBuilderSize(const QString &a) { return a.size(); }
inline int qStringBuilderSize(const QStringRef &a) { return a.size(); }
template <typename A, typename B>
inline int qStringBuilderSize(const QStringBuilderPair<A, B> &p)
{
return qStringBuilderSize(p.a) + qStringBuilderSize(p.b);
}
template <typename A, typename B> class QStringBuilder;
template <typename A, typename B>
inline int qStringBuilderSize(const QStringBuilder<A, B> &p);
inline void qStringBuilderAppend(const char c, QChar *&out)
{
......@@ -156,42 +143,55 @@ inline void qStringBuilderAppend(const QLatin1Literal &a, QChar *&out)
}
template <typename A, typename B>
inline void qStringBuilderAppend(const QStringBuilderPair<A, B> &p, QChar *&out)
{
qStringBuilderAppend(p.a, out);
qStringBuilderAppend(p.b, out);
}
} // Qt
inline void qStringBuilderAppend(const QStringBuilder<A, B> &p, QChar
*&out);
template <typename A>
class QStringBuilder : public A
template <typename A, typename B>
class QStringBuilder
{
public:
QStringBuilder(const A &a_) : A(a_) {}
QStringBuilder(const A &a_, const B &b_) : a(a_), b(b_) {}
operator QString() const
{
#ifdef USE_CHANGED_QSTRING
#ifdef USE_CHANGED_QSTRING
QString s(this->size(), QChar(-1));
#else
#else
QString s;
s.resize(Qt::qStringBuilderSize(*this));
#endif
#endif
QChar *d = s.data();
Qt::qStringBuilderAppend(*this, d);
return s;
}
public:
const A &a;
const B &b;
};
template <typename A, typename B>
QStringBuilder< QStringBuilderPair<A, B> >
inline int qStringBuilderSize(const QStringBuilder<A, B> &p)
{
return qStringBuilderSize(p.a) + qStringBuilderSize(p.b);
}
template <typename A, typename B>
inline void qStringBuilderAppend(const QStringBuilder<A, B> &p, QChar *&out)
{
qStringBuilderAppend(p.a, out);
qStringBuilderAppend(p.b, out);
}
} // Qt
template <typename A, typename B>
Qt::QStringBuilder<A, B>
operator%(const A &a, const B &b)
{
return QStringBuilderPair<A, B> (a, b);
return Qt::QStringBuilder<A, B>(a, b);
}
......
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