diff options
author | Sérgio Martins <sergio.martins@kdab.com> | 2015-04-21 21:32:19 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-04-24 06:56:15 +0000 |
commit | 1c33c37d4c237a1e43b431f95a827dd219a1f10a (patch) | |
tree | 723aad840198310cdd1aeb80350511b7be31d641 /src/corelib | |
parent | 3378aa45c27052510c244f935639d65bdf9275f4 (diff) |
QVector: Save one copy-CTOR call if we don't realloc
Change-Id: Ie0f2eb922500bc3d76852939cf2c5d28d65a43ae
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qvector.h | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 9d5b749e79..eed5d17cad 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -600,16 +600,23 @@ Q_OUTOFLINE_TEMPLATE T QVector<T>::value(int i, const T &defaultValue) const template <typename T> void QVector<T>::append(const T &t) { - const T copy(t); const bool isTooSmall = uint(d->size + 1) > d->alloc; if (!isDetached() || isTooSmall) { + const T copy(t); QArrayData::AllocationOptions opt(isTooSmall ? QArrayData::Grow : QArrayData::Default); reallocData(d->size, isTooSmall ? d->size + 1 : d->alloc, opt); + + if (QTypeInfo<T>::isComplex) + new (d->end()) T(copy); + else + *d->end() = copy; + + } else { + if (QTypeInfo<T>::isComplex) + new (d->end()) T(t); + else + *d->end() = t; } - if (QTypeInfo<T>::isComplex) - new (d->end()) T(copy); - else - *d->end() = copy; ++d->size; } |