diff options
author | Liang Qi <liang.qi@nokia.com> | 2011-05-10 11:38:53 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@nokia.com> | 2011-05-10 11:38:53 +0200 |
commit | 44b7877c879faabe83310df697d1ec2f013ee8b5 (patch) | |
tree | 296935b08c12c186bb374a66e4987ed8a03b8d65 /src/corelib | |
parent | 939886720920f907884b8b32bf501354ed805857 (diff) |
Respect capacity in QVector::append().
Fix a bug in QVector::append(), it should use the capacity for new size,
when it is implicit shared and capacity is bigger than the new size.
Autotest included.
Task-number: QTBUG-11763
Reviewed-by: joao
Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qvector.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 9418642752..6f068dc4b0 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -574,8 +574,9 @@ void QVector<T>::append(const T &t) { if (d->ref != 1 || d->size + 1 > d->alloc) { const T copy(t); - realloc(d->size, QVectorData::grow(sizeOfTypedData(), d->size + 1, sizeof(T), - QTypeInfo<T>::isStatic)); + realloc(d->size, (d->size + 1 > d->alloc) ? + QVectorData::grow(sizeOfTypedData(), d->size + 1, sizeof(T), QTypeInfo<T>::isStatic) + : d->alloc); if (QTypeInfo<T>::isComplex) new (p->array + d->size) T(copy); else |