From e5a20cb864aba3fc9ca6814e54c62b0e25cffb2d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 13 Dec 2015 03:40:56 +0100 Subject: [PATCH] QString: mark relational operators (and compare()) nothrow Saves ~3K in QtCore text size on GCC 4.9 Linux AMD64 relase builds. Change-Id: I74171ba5499de200b9584660241ca1fae4bcad79 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qstring.cpp | 26 ++++----- src/corelib/tools/qstring.h | 99 ++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index fa023d57db..b582204d67 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -2671,7 +2671,7 @@ QString &QString::replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs) expect. Consider sorting user-interface strings with localeAwareCompare(). */ -bool operator==(const QString &s1, const QString &s2) +bool operator==(const QString &s1, const QString &s2) Q_DECL_NOTHROW { if (s1.d->size != s2.d->size) return false; @@ -2684,7 +2684,7 @@ bool operator==(const QString &s1, const QString &s2) Returns \c true if this string is equal to \a other; otherwise returns \c false. */ -bool QString::operator==(QLatin1String other) const +bool QString::operator==(QLatin1String other) const Q_DECL_NOTHROW { if (d->size != other.size()) return false; @@ -2735,7 +2735,7 @@ bool QString::operator==(QLatin1String other) const expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function. */ -bool operator<(const QString &s1, const QString &s2) +bool operator<(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0; } @@ -2745,7 +2745,7 @@ bool operator<(const QString &s1, const QString &s2) Returns \c true if this string is lexically less than the parameter string called \a other; otherwise returns \c false. */ -bool QString::operator<(QLatin1String other) const +bool QString::operator<(QLatin1String other) const Q_DECL_NOTHROW { const uchar *c = (const uchar *) other.latin1(); if (!c || *c == 0) @@ -2850,7 +2850,7 @@ bool QString::operator<(QLatin1String other) const Returns \c true if this string is lexically greater than the parameter string \a other; otherwise returns \c false. */ -bool QString::operator>(QLatin1String other) const +bool QString::operator>(QLatin1String other) const Q_DECL_NOTHROW { const uchar *c = (const uchar *) other.latin1(); if (!c || *c == '\0') @@ -5333,7 +5333,7 @@ QString& QString::fill(QChar ch, int size) Same as compare(*this, \a other, \a cs). */ -int QString::compare(const QString &other, Qt::CaseSensitivity cs) const +int QString::compare(const QString &other, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW { if (cs == Qt::CaseSensitive) return ucstrcmp(constData(), length(), other.constData(), other.length()); @@ -5345,7 +5345,7 @@ int QString::compare(const QString &other, Qt::CaseSensitivity cs) const \since 4.5 */ int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, - Qt::CaseSensitivity cs) + Qt::CaseSensitivity cs) Q_DECL_NOTHROW { if (cs == Qt::CaseSensitive) return ucstrcmp(data1, length1, data2, length2); @@ -5360,7 +5360,7 @@ int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, Same as compare(*this, \a other, \a cs). */ -int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const +int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW { return compare_helper(unicode(), length(), other, cs); } @@ -5396,7 +5396,7 @@ int QString::compare_helper(const QChar *data1, int length1, const char *data2, \since 4.5 */ int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, - Qt::CaseSensitivity cs) + Qt::CaseSensitivity cs) Q_DECL_NOTHROW { const ushort *uc = reinterpret_cast(data1); const ushort *uce = uc + length1; @@ -8907,7 +8907,7 @@ QString QStringRef::toString() const { Returns \c true if string reference \a s1 is lexically equal to string reference \a s2; otherwise returns \c false. */ -bool operator==(const QStringRef &s1,const QStringRef &s2) +bool operator==(const QStringRef &s1,const QStringRef &s2) Q_DECL_NOTHROW { return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size())); } @@ -8917,7 +8917,7 @@ bool operator==(const QStringRef &s1,const QStringRef &s2) Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise returns \c false. */ -bool operator==(const QString &s1,const QStringRef &s2) +bool operator==(const QString &s1,const QStringRef &s2) Q_DECL_NOTHROW { return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size())); } @@ -8927,7 +8927,7 @@ bool operator==(const QString &s1,const QStringRef &s2) Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise returns \c false. */ -bool operator==(QLatin1String s1, const QStringRef &s2) +bool operator==(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW { if (s1.size() != s2.size()) return false; @@ -8949,7 +8949,7 @@ bool operator==(QLatin1String s1, const QStringRef &s2) expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function. */ -bool operator<(const QStringRef &s1,const QStringRef &s2) +bool operator<(const QStringRef &s1,const QStringRef &s2) Q_DECL_NOTHROW { return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0; } diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 5894b869da..4ae81f9269 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -571,22 +571,23 @@ public: QString &setUnicode(const QChar *unicode, int size); inline QString &setUtf16(const ushort *utf16, int size); - int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; - static inline int compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) + static inline int compare(const QString &s1, const QString &s2, + Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW { return s1.compare(s2, cs); } static inline int compare(const QString &s1, QLatin1String s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) + Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW { return s1.compare(s2, cs); } static inline int compare(QLatin1String s1, const QString &s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive) + Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW { return -s2.compare(s1, cs); } - int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; static int compare(const QString &s1, const QStringRef &s2, - Qt::CaseSensitivity = Qt::CaseSensitive); + Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW; int localeAwareCompare(const QString& s) const; static int localeAwareCompare(const QString& s1, const QString& s2) @@ -626,19 +627,19 @@ public: static QString number(qulonglong, int base=10); static QString number(double, char f='g', int prec=6); - friend Q_CORE_EXPORT bool operator==(const QString &s1, const QString &s2); - friend Q_CORE_EXPORT bool operator<(const QString &s1, const QString &s2); - friend inline bool operator>(const QString &s1, const QString &s2) { return s2 < s1; } - friend inline bool operator!=(const QString &s1, const QString &s2) { return !(s1 == s2); } - friend inline bool operator<=(const QString &s1, const QString &s2) { return !(s1 > s2); } - friend inline bool operator>=(const QString &s1, const QString &s2) { return !(s1 < s2); } + friend Q_CORE_EXPORT bool operator==(const QString &s1, const QString &s2) Q_DECL_NOTHROW; + friend Q_CORE_EXPORT bool operator<(const QString &s1, const QString &s2) Q_DECL_NOTHROW; + friend inline bool operator>(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return s2 < s1; } + friend inline bool operator!=(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return !(s1 == s2); } + friend inline bool operator<=(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return !(s1 > s2); } + friend inline bool operator>=(const QString &s1, const QString &s2) Q_DECL_NOTHROW { return !(s1 < s2); } - bool operator==(QLatin1String s) const; - bool operator<(QLatin1String s) const; - bool operator>(QLatin1String s) const; - inline bool operator!=(QLatin1String s) const { return !operator==(s); } - inline bool operator<=(QLatin1String s) const { return !operator>(s); } - inline bool operator>=(QLatin1String s) const { return !operator<(s); } + bool operator==(QLatin1String s) const Q_DECL_NOTHROW; + bool operator<(QLatin1String s) const Q_DECL_NOTHROW; + bool operator>(QLatin1String s) const Q_DECL_NOTHROW; + inline bool operator!=(QLatin1String s) const Q_DECL_NOTHROW { return !operator==(s); } + inline bool operator<=(QLatin1String s) const Q_DECL_NOTHROW { return !operator>(s); } + inline bool operator>=(QLatin1String s) const Q_DECL_NOTHROW { return !operator<(s); } // ASCII compatibility #if defined(QT_RESTRICTED_CAST_FROM_ASCII) @@ -798,13 +799,13 @@ private: QString multiArg(int numArgs, const QString **args) const; static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, - Qt::CaseSensitivity cs = Qt::CaseSensitive); + Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; static int compare_helper(const QChar *data1, int length1, const char *data2, int length2, Qt::CaseSensitivity cs = Qt::CaseSensitive); static int compare_helper(const QChar *data1, int length1, QLatin1String s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive); + Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; static int localeAwareCompare_helper(const QChar *data1, int length1, const QChar *data2, int length2); static QString toLower_helper(const QString &str); @@ -1469,15 +1470,15 @@ public: inline QT_ASCII_CAST_WARN bool operator>=(const char *s) const; #endif - int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; static int compare(const QStringRef &s1, const QString &s2, - Qt::CaseSensitivity = Qt::CaseSensitive); + Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW; static int compare(const QStringRef &s1, const QStringRef &s2, - Qt::CaseSensitivity = Qt::CaseSensitive); + Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW; static int compare(const QStringRef &s1, QLatin1String s2, - Qt::CaseSensitivity cs = Qt::CaseSensitive); + Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; int localeAwareCompare(const QString &s) const; int localeAwareCompare(const QStringRef &s) const; @@ -1507,30 +1508,30 @@ inline QStringRef::QStringRef(const QString *aString, int aPosition, int aSize) inline QStringRef::QStringRef(const QString *aString) :m_string(aString), m_position(0), m_size(aString?aString->size() : 0){} -Q_CORE_EXPORT bool operator==(const QStringRef &s1,const QStringRef &s2); -inline bool operator!=(const QStringRef &s1,const QStringRef &s2) +Q_CORE_EXPORT bool operator==(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW; +inline bool operator!=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW { return !(s1 == s2); } -Q_CORE_EXPORT bool operator==(const QString &s1,const QStringRef &s2); -inline bool operator!=(const QString &s1,const QStringRef &s2) +Q_CORE_EXPORT bool operator==(const QString &s1, const QStringRef &s2) Q_DECL_NOTHROW; +inline bool operator!=(const QString &s1, const QStringRef &s2) Q_DECL_NOTHROW { return !(s1 == s2); } -inline bool operator==(const QStringRef &s1,const QString &s2) +inline bool operator==(const QStringRef &s1, const QString &s2) Q_DECL_NOTHROW { return s2 == s1; } -inline bool operator!=(const QStringRef &s1,const QString &s2) +inline bool operator!=(const QStringRef &s1, const QString &s2) Q_DECL_NOTHROW { return s2 != s1; } -Q_CORE_EXPORT bool operator==(QLatin1String s1, const QStringRef &s2); -inline bool operator!=(QLatin1String s1, const QStringRef &s2) +Q_CORE_EXPORT bool operator==(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW; +inline bool operator!=(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW { return !(s1 == s2); } -inline bool operator==(const QStringRef &s1, QLatin1String s2) +inline bool operator==(const QStringRef &s1, QLatin1String s2) Q_DECL_NOTHROW { return s2 == s1; } -inline bool operator!=(const QStringRef &s1, QLatin1String s2) +inline bool operator!=(const QStringRef &s1, QLatin1String s2) Q_DECL_NOTHROW { return s2 != s1; } -Q_CORE_EXPORT bool operator<(const QStringRef &s1,const QStringRef &s2); -inline bool operator>(const QStringRef &s1, const QStringRef &s2) +Q_CORE_EXPORT bool operator<(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW; +inline bool operator>(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW { return s2 < s1; } -inline bool operator<=(const QStringRef &s1, const QStringRef &s2) +inline bool operator<=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW { return !(s1 > s2); } -inline bool operator>=(const QStringRef &s1, const QStringRef &s2) +inline bool operator>=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW { return !(s1 < s2); } #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) @@ -1561,21 +1562,21 @@ inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2) { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; } #endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) -inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const +inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) +inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const +inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const +inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } -inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const +inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW { return QString::compare_helper(constData(), length(), s, cs); } -inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) +inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) +inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); } -inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) +inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return QString::compare_helper(s1.constData(), s1.length(), s2, cs); } inline int QString::localeAwareCompare(const QStringRef &s) const