After allocating memory on the heap it is ATM not possible to use the
memory on the stack again, QVarLengthArray then uses/resizes only
the memory on the heap. But the memory on stack could be used
if it is big enough.
Change-Id: I566003c25dd1093eb6ba8087a1e5378a11712934
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
const int copySize = qMin(asize, osize);
if (aalloc != a) {
const int copySize = qMin(asize, osize);
if (aalloc != a) {
- T* newPtr = reinterpret_cast<T *>(malloc(aalloc * sizeof(T)));
- Q_CHECK_PTR(newPtr); // could throw
- // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here
- ptr = newPtr;
+ if (aalloc > Prealloc) {
+ T* newPtr = reinterpret_cast<T *>(malloc(aalloc * sizeof(T)));
+ Q_CHECK_PTR(newPtr); // could throw
+ // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here
+ ptr = newPtr;
+ a = aalloc;
+ } else {
+ ptr = reinterpret_cast<T *>(array);
+ a = Prealloc;
+ }
if (QTypeInfo<T>::isStatic) {
QT_TRY {
// copy all the old elements
if (QTypeInfo<T>::isStatic) {
QT_TRY {
// copy all the old elements