diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-08-31 13:00:13 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-09-09 17:19:27 +0000 |
commit | 6549bd383d64881ba6b9dad8529fd904d17da100 (patch) | |
tree | d985f4368ee6fd71d2eea5b1d9e7ff73b8a58499 /src/corelib | |
parent | 806b45e7c76f6825e32fde10824beb62eecc40ab (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/corelib')
-rw-r--r-- | src/corelib/global/qglobal.h | 7 |
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: |