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>
This commit is contained in:
parent
5b1bc864a9
commit
3a48320fd6
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user