From 52f3a7d9d40d3bf835bb0716ad201ee56731b980 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 3 Apr 2020 11:49:27 +0200 Subject: Build qmake with QT_USE_STRINGBUILDER Should improve performance and is going to be required in the future anyway. Change-Id: I89d7c50441d2491da1ab0a4d564dcc91f52ade85 Reviewed-by: Alex Blasche --- qmake/library/proitems.h | 74 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 20 deletions(-) (limited to 'qmake/library') diff --git a/qmake/library/proitems.h b/qmake/library/proitems.h index 333f9ed889..09c5504fdf 100644 --- a/qmake/library/proitems.h +++ b/qmake/library/proitems.h @@ -70,9 +70,16 @@ public: ProString(); ProString(const ProString &other); ProString &operator=(const ProString &) = default; - PROITEM_EXPLICIT ProString(const QString &str); + template + ProString &operator=(const QStringBuilder &str) + { return *this = QString(str); } + ProString(const QString &str); PROITEM_EXPLICIT ProString(const QStringRef &str); PROITEM_EXPLICIT ProString(const char *str); + template + ProString(const QStringBuilder &str) + : ProString(QString(str)) + {} ProString(const QString &str, int offset, int length); void setValue(const QString &str); void clear() { m_string.clear(); m_length = 0; } @@ -83,12 +90,16 @@ public: ProString &prepend(const ProString &other); ProString &append(const ProString &other, bool *pending = nullptr); ProString &append(const QString &other) { return append(ProString(other)); } + template + ProString &append(const QStringBuilder &other) { return append(QString(other)); } ProString &append(const QLatin1String other); ProString &append(const char *other) { return append(QLatin1String(other)); } ProString &append(QChar other); ProString &append(const ProStringList &other, bool *pending = nullptr, bool skipEmpty1st = false); ProString &operator+=(const ProString &other) { return append(other); } ProString &operator+=(const QString &other) { return append(other); } + template + ProString &operator+=(const QStringBuilder &other) { return append(QString(other)); } ProString &operator+=(const QLatin1String other) { return append(other); } ProString &operator+=(const char *other) { return append(other); } ProString &operator+=(QChar other) { return append(other); } @@ -123,9 +134,13 @@ public: bool startsWith(const QString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().startsWith(sub, cs); } bool startsWith(const char *sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().startsWith(QLatin1String(sub), cs); } bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().startsWith(c, cs); } + template + bool startsWith(const QStringBuilder &str) { return startsWith(QString(str)); } bool endsWith(const ProString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().endsWith(sub.toQStringRef(), cs); } bool endsWith(const QString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().endsWith(sub, cs); } bool endsWith(const char *sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().endsWith(QLatin1String(sub), cs); } + template + bool endsWith(const QStringBuilder &str) { return endsWith(QString(str)); } bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().endsWith(c, cs); } int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().indexOf(s, from, cs); } int indexOf(const char *s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().indexOf(QLatin1String(s), from, cs); } @@ -179,10 +194,15 @@ private: }; Q_DECLARE_TYPEINFO(ProString, Q_MOVABLE_TYPE); + class ProKey : public ProString { public: ALWAYS_INLINE ProKey() : ProString() {} explicit ProKey(const QString &str); + template + ProKey(const QStringBuilder &str) + : ProString(str) + {} PROITEM_EXPLICIT ProKey(const char *str); ProKey(const QString &str, int off, int len); ProKey(const QString &str, int off, int len, uint hash); @@ -206,31 +226,43 @@ private: }; Q_DECLARE_TYPEINFO(ProKey, Q_MOVABLE_TYPE); +template <> struct QConcatenable : private QAbstractConcatenable +{ + typedef ProString type; + typedef QString ConvertTo; + enum { ExactSize = true }; + static int size(const ProString &a) { return a.length(); } + static inline void appendTo(const ProString &a, QChar *&out) + { + const auto n = a.size(); + memcpy(out, a.toQStringView().data(), sizeof(QChar) * n); + out += n; + } +}; + +template <> struct QConcatenable : private QAbstractConcatenable +{ + typedef ProKey type; + typedef QString ConvertTo; + enum { ExactSize = true }; + static int size(const ProKey &a) { return a.length(); } + static inline void appendTo(const ProKey &a, QChar *&out) + { + const auto n = a.size(); + memcpy(out, a.toQStringView().data(), sizeof(QChar) * n); + out += n; + } +}; + + size_t qHash(const ProString &str); -QString operator+(const ProString &one, const ProString &two); -inline QString operator+(const ProString &one, const QString &two) - { return one.toQStringRef() + two; } -inline QString operator+(const QString &one, const ProString &two) - { return one + two.toQStringRef(); } - -inline QString operator+(const ProString &one, const char *two) - { return one.toQStringRef() + QLatin1String(two); } -inline QString operator+(const char *one, const ProString &two) - { return QLatin1String(one) + two.toQStringRef(); } -inline QString operator+(const ProString &one, QChar two) - { return one.toQStringRef() + two; } -inline QString operator+(QChar one, const ProString &two) - { return one + two.toQStringRef(); } inline QString &operator+=(QString &that, const ProString &other) { return that += other.toQStringRef(); } -inline bool operator==(const QString &that, const ProString &other) - { return other == that; } -inline bool operator!=(const QString &that, const ProString &other) - { return !(other == that); } - QTextStream &operator<<(QTextStream &t, const ProString &str); +template +QTextStream &operator<<(QTextStream &t, const QStringBuilder &str) { return t << QString(str); } // This class manages read-only access to a ProString via a raw data QString // temporary, ensuring that the latter is accessed exclusively. @@ -296,6 +328,8 @@ public: QString join(const ProString &sep) const; QString join(const QString &sep) const; QString join(QChar sep) const; + template + QString join(const QStringBuilder &str) { return join(QString(str)); } void insertUnique(const ProStringList &value); -- cgit v1.2.3