summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-03-25 00:28:19 +0100
committerMarc Mutz <marc.mutz@kdab.com>2014-08-24 13:42:42 +0200
commite3e4fe79100162a9fc47b923fe23d1a296cd67d1 (patch)
treef362b582bb229d4d036d87b093f474b168ab3eb1 /src/corelib/tools
parentb98381821900154276ce207799293a00a5f40f0e (diff)
Use std::vector range ctor in QVector::toStdVector()
There are three reasons to do so: 1. This could be more efficient, depending on the STL implementation. 2. By using QTypedArrayData iterators (T*) instead of QVector ones, we actually invoke the non-templated range ctor of std::vector, at least in the common case that std::vector<T>::const_iterator is also const T*. 3. The change turns a former NRVO return into a RVO one, potentially allowing more compilers to perform the copy elision. Change-Id: I70b35aaeae70ba06a971a36b8b1b1da997e8094f Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qvector.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index f09f1a3c41..c92f43e1fc 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -256,7 +256,7 @@ public:
static inline QVector<T> fromStdVector(const std::vector<T> &vector)
{ QVector<T> tmp; tmp.reserve(int(vector.size())); std::copy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
inline std::vector<T> toStdVector() const
- { std::vector<T> tmp; tmp.reserve(size()); std::copy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
+ { return std::vector<T>(d->begin(), d->end()); }
private:
friend class QRegion; // Optimization for QRegion::rects()