From 6549bd383d64881ba6b9dad8529fd904d17da100 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 31 Aug 2016 13:00:13 +0200 Subject: 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) --- src/corelib/global/qglobal.h | 7 ++++--- 1 file 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 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: -- cgit v1.2.3