Don't grow container when desired size is known
authorJoão Abecasis <joao.abecasis@nokia.com>
Wed, 7 Mar 2012 22:17:54 +0000 (23:17 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 9 Mar 2012 20:26:40 +0000 (21:26 +0100)
commit3c94c7eb7e622051677eb319f6a79e5edb8e2a12
treeecead298d8152cf6676c217b20213f71bf5b66c6
parent8fd3c019169c45fbc6c8f29b69dc4c17fc8e4187
Don't grow container when desired size is known

QList<Type>::reserve() is used upfront to allocate necessary memory in a one
go. This tells us straight away whether allocation is possible at all and
reduces re-allocations and consequent memory copies.

This also has the side effect that no spare memory is allocated, also allowing
up to (and including) INT_MAX elements to actually be stored in the underlying
QList, as long as enough memory is available to satisfy the allocation request
and subsequent fill.

The qqmlecmascript::sequenceConversionIndexes was changed to not attempt
INT_MAX allocations as, given enough memory and virtual address space, that
might succeed but take a really long time.

Change-Id: I4b0c965e9c23be78874343a70d7c155933c80903
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
src/qml/qml/v8/qv8sequencewrapper_p_p.h
tests/auto/qml/qqmlecmascript/data/sequenceConversion.indexes.qml
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp