summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qvector.h
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-02-16 23:53:58 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-17 21:23:20 +0100
commitfd96115ae8501c2baf591b821bdf6f7d90b62f55 (patch)
treeca3a0e45a0e998e0c9e54e4ed7e1ef65b353e9e2 /src/corelib/tools/qvector.h
parentfb8be9905d5f3216edc3fbb72b8ce1c380737eac (diff)
QVector: always grow exponentially
For non-movable types (QTypeInfo<T>::isStatic), QVector would grow the array linearly, and defer to qAllocMore otherwise. That property, however, gives no indication as to how the vector will grow. By forcing additional allocations for growing containers of such types, this penalized exactly those objects which are more expensive to move. We now let qAllocMore reign in growth decisions. Change-Id: I843a89dcdc21d09868c6b62a846a7e1e4548e399 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/tools/qvector.h')
-rw-r--r--src/corelib/tools/qvector.h9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 6357c24621..4f9e1839ec 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -80,7 +80,7 @@ struct Q_CORE_EXPORT QVectorData
static QVectorData *allocate(int size, int alignment);
static QVectorData *reallocate(QVectorData *old, int newsize, int oldsize, int alignment);
static void free(QVectorData *data, int alignment);
- static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive);
+ static int grow(int sizeofTypedData, int size, int sizeofT);
};
template <typename T>
@@ -355,7 +355,7 @@ void QVector<T>::reserve(int asize)
template <typename T>
void QVector<T>::resize(int asize)
{ realloc(asize, (asize > d->alloc || (!d->capacity && asize < d->size && asize < (d->alloc >> 1))) ?
- QVectorData::grow(sizeOfTypedData(), asize, sizeof(T), QTypeInfo<T>::isStatic)
+ QVectorData::grow(sizeOfTypedData(), asize, sizeof(T))
: d->alloc); }
template <typename T>
inline void QVector<T>::clear()
@@ -582,7 +582,7 @@ void QVector<T>::append(const T &t)
if (!isDetached() || d->size + 1 > d->alloc) {
const T copy(t);
realloc(d->size, (d->size + 1 > d->alloc) ?
- QVectorData::grow(sizeOfTypedData(), d->size + 1, sizeof(T), QTypeInfo<T>::isStatic)
+ QVectorData::grow(sizeOfTypedData(), d->size + 1, sizeof(T))
: d->alloc);
if (QTypeInfo<T>::isComplex)
new (p->array + d->size) T(copy);
@@ -604,8 +604,7 @@ typename QVector<T>::iterator QVector<T>::insert(iterator before, size_type n, c
if (n != 0) {
const T copy(t);
if (!isDetached() || d->size + n > d->alloc)
- realloc(d->size, QVectorData::grow(sizeOfTypedData(), d->size + n, sizeof(T),
- QTypeInfo<T>::isStatic));
+ realloc(d->size, QVectorData::grow(sizeOfTypedData(), d->size + n, sizeof(T)));
if (QTypeInfo<T>::isStatic) {
T *b = p->array + d->size;
T *i = p->array + d->size + n;