summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-08-31 13:00:13 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-09-09 17:19:27 +0000
commit6549bd383d64881ba6b9dad8529fd904d17da100 (patch)
treed985f4368ee6fd71d2eea5b1d9e7ff73b8a58499 /src
parent806b45e7c76f6825e32fde10824beb62eecc40ab (diff)
Optimize Q_FOREACH for rvalues
Add an rvalue overload of the QForeachContainer ctor to allow moving rvalues into the internal container copy. This does not change the semantics of Q_FOREACH. It is just an optimization. Port to NSDMI to minimize code duplication. Costs ~1.3KiB across all libraries and plugins in a QtBase Linux build (optimized GCC 6.1 AMD64). Change-Id: I180e35ecab68aa1d37773b3546787481bb5515a2 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qglobal.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index e6d65b0f99..c463a392b7 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -943,10 +943,11 @@ template <typename T>
class QForeachContainer {
QForeachContainer &operator=(const QForeachContainer &) Q_DECL_EQ_DELETE;
public:
- inline QForeachContainer(const T& t) : c(t), i(c.begin()), e(c.end()), control(1) { }
+ QForeachContainer(const T &t) : c(t) {}
+ QForeachContainer(T &&t) : c(std::move(t)) {}
const T c;
- typename T::const_iterator i, e;
- int control;
+ typename T::const_iterator i = c.begin(), e = c.end();
+ int control = 1;
};
// Explanation of the control word: