diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-02-17 12:52:35 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-02-17 16:42:15 (GMT) |
commit | 8653f5a3233bff64ec7438fb5e38a6df57dce10e (patch) | |
tree | 3a052e0b122d611179b8b76dcc0b6898fdb9f1c1 /src | |
parent | 5084d1694e62c3c704c83cc0f27afb6a39b20781 (diff) | |
download | Qt-8653f5a3233bff64ec7438fb5e38a6df57dce10e.zip Qt-8653f5a3233bff64ec7438fb5e38a6df57dce10e.tar.gz Qt-8653f5a3233bff64ec7438fb5e38a6df57dce10e.tar.bz2 |
optimization: use QList::reserve() and QVector::reserve()
Co-authored-by: denis
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qvector.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 61b22fd..2fc4d6c 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -728,9 +728,10 @@ Q_OUTOFLINE_TEMPLATE QVector<T> QVector<T>::mid(int pos, int length) const length = size() - pos; if (pos == 0 && length == size()) return *this; - QVector<T> copy; if (pos + length > size()) length = size() - pos; + QVector<T> copy; + copy.reserve(length); for (int i = pos; i < pos + length; ++i) copy += at(i); return copy; @@ -740,6 +741,7 @@ template <typename T> Q_OUTOFLINE_TEMPLATE QList<T> QVector<T>::toList() const { QList<T> result; + result.reserve(size()); for (int i = 0; i < size(); ++i) result.append(at(i)); return result; |