summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-07-28 19:50:35 -0700
committerThiago Macieira <thiago.macieira@intel.com>2014-11-02 20:51:57 +0100
commit294c914eb6bb5e0200480400ba31f2049edb9b86 (patch)
tree86fe3198ebc56f63efb2ea136be88e15a708368b /src/corelib/tools/qbytearray.h
parent939197fd7c8b64256333d096f3b4ebbf066b2481 (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/qbytearray.h')
-rw-r--r--src/corelib/tools/qbytearray.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index 46aaeba1b5..6976124bca 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -272,16 +272,24 @@ public:
{ return toUpper_helper(*this); }
QByteArray toUpper() && Q_REQUIRED_RESULT
{ return toUpper_helper(*this); }
+ QByteArray trimmed() const & Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QByteArray trimmed() && Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QByteArray simplified() const & Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+ QByteArray simplified() && Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
# ifdef Q_REQUIRED_RESULT_pushed
# pragma pop_macro("Q_REQUIRED_RESULT")
# endif
#else
QByteArray toLower() const Q_REQUIRED_RESULT;
QByteArray toUpper() const Q_REQUIRED_RESULT;
-#endif
-
QByteArray trimmed() const Q_REQUIRED_RESULT;
QByteArray simplified() const Q_REQUIRED_RESULT;
+#endif
+
QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT;
QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT;
@@ -439,6 +447,11 @@ private:
static QByteArray toLower_helper(QByteArray &a);
static QByteArray toUpper_helper(const QByteArray &a);
static QByteArray toUpper_helper(QByteArray &a);
+ static QByteArray trimmed_helper(const QByteArray &a);
+ static QByteArray trimmed_helper(QByteArray &a);
+ static QByteArray simplified_helper(const QByteArray &a);
+ static QByteArray simplified_helper(QByteArray &a);
+
friend class QByteRef;
friend class QString;
friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes);