summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-09-07 10:02:04 +0200
committerQt by Nokia <qt-info@nokia.com>2012-09-07 18:41:22 +0200
commit3a48320fd6335d21451f07cb68336404177e2d87 (patch)
tree598a446840aad5740703c5019a44062c22a0c00a /src/corelib
parent5b1bc864a91c3bdb02e36e7546dadebabb42fdec (diff)
Fix performance regression when appending one vector to another
When appending a QVector to an existing vector the code would unconditionally realloc the vector instead of first checking whether we can do without. This gives a quadratic behaviour when repeatedly appending a vector to another. Change-Id: I2cd81253e6a8aec0bc4402e6fbda262435080966 Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org> Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qvector.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index f3ef9b97c3..e52fb9a1be 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -650,8 +650,12 @@ QVector<T> &QVector<T>::fill(const T &from, int asize)
template <typename T>
QVector<T> &QVector<T>::operator+=(const QVector &l)
{
- int newSize = d->size + l.d->size;
- reallocData(d->size, newSize);
+ uint newSize = d->size + l.d->size;
+ const bool isTooSmall = newSize > d->alloc;
+ if (!isDetached() || isTooSmall) {
+ QArrayData::AllocationOptions opt(isTooSmall ? QArrayData::Grow : QArrayData::Default);
+ reallocData(d->size, isTooSmall ? newSize : d->alloc, opt);
+ }
if (d->alloc) {
T *w = d->begin() + newSize;