summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@digia.com>2014-02-19 11:27:50 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-16 18:24:14 +0200
commit39efc7c3e3a08580f00a19678d2975608d41aa17 (patch)
tree9083859152bb7ee394da5edd61bde5975fa47cbe /src/corelib/tools
parent7c17b0ad2b74086a52aa6b66c1673335ce65bd5b (diff)
Optimize QVector::mid
Change-Id: Iff7d9ec85a095c6712e6045e7708bb88eac629e1 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qvector.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 9692477e18..c547cec7be 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -833,11 +833,13 @@ Q_OUTOFLINE_TEMPLATE QVector<T> QVector<T>::mid(int pos, int len) const
break;
}
- QVector<T> copy;
- copy.reserve(len);
- for (int i = pos; i < pos + len; ++i)
- copy += at(i);
- return copy;
+ QVector<T> midResult;
+ midResult.reallocData(0, len);
+ T *srcFrom = d->begin() + pos;
+ T *srcTo = d->begin() + pos + len;
+ midResult.copyConstruct(srcFrom, srcTo, midResult.data());
+ midResult.d->size = len;
+ return midResult;
}
template <typename T>