diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-07-28 19:50:35 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2014-11-02 20:51:57 +0100 |
commit | 294c914eb6bb5e0200480400ba31f2049edb9b86 (patch) | |
tree | 86fe3198ebc56f63efb2ea136be88e15a708368b /src/corelib/tools/qstring.h | |
parent | 939197fd7c8b64256333d096f3b4ebbf066b2481 (diff) |
Add rvalue-ref qualified {QString,QByteArray}::{simplified,trimmed}
Of the const overloads that return a QString or a QByteArray, this is
one that gains the most benefit. It happens often in constructs like:
QByteArray s = x.readLine().trimmed();
After this change, 41 out of 103 calls to trimmed become rvalue in Qt
and 272 out of 441 in Qt Creator. For simplified, the numbers are 27 out
of 69 in Qt and 10 out of 19 in Qt Creator.
Other candidates are left, right, and mid, but there are exactly zero
uses of left, right and mid on an xvalue QString or QByteArray in Qt.
I'm being lazy and using qstring_compat.cpp to store the QByteArray
compat methods.
Change-Id: I4e410fc1adc4c761bb07cc3d43b348a65befa9f6
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r-- | src/corelib/tools/qstring.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index a84179e1e6..718f10860a 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -395,6 +395,14 @@ public: { return toCaseFolded_helper(*this); } QString toCaseFolded() && Q_REQUIRED_RESULT { return toCaseFolded_helper(*this); } + QString trimmed() const & Q_REQUIRED_RESULT + { return trimmed_helper(*this); } + QString trimmed() && Q_REQUIRED_RESULT + { return trimmed_helper(*this); } + QString simplified() const & Q_REQUIRED_RESULT + { return simplified_helper(*this); } + QString simplified() && Q_REQUIRED_RESULT + { return simplified_helper(*this); } # ifdef Q_REQUIRED_RESULT_pushed # pragma pop_macro("Q_REQUIRED_RESULT") # endif @@ -402,10 +410,9 @@ public: QString toLower() const Q_REQUIRED_RESULT; QString toUpper() const Q_REQUIRED_RESULT; QString toCaseFolded() const Q_REQUIRED_RESULT; -#endif - QString trimmed() const Q_REQUIRED_RESULT; QString simplified() const Q_REQUIRED_RESULT; +#endif QString toHtmlEscaped() const Q_REQUIRED_RESULT; QString &insert(int i, QChar c); @@ -780,6 +787,10 @@ private: static QString toUpper_helper(QString &str); static QString toCaseFolded_helper(const QString &str); static QString toCaseFolded_helper(QString &str); + static QString trimmed_helper(const QString &str); + static QString trimmed_helper(QString &str); + static QString simplified_helper(const QString &str); + static QString simplified_helper(QString &str); static Data *fromLatin1_helper(const char *str, int size = -1); static Data *fromAscii_helper(const char *str, int size = -1); static QString fromUtf8_helper(const char *str, int size); |