diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 90b10a3ed13..0c5b61d68af 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -252,12 +252,17 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::realloc(int asize, int a const int copySize = qMin(asize, osize); if (aalloc != a) { - T* newPtr = reinterpret_cast(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(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(array); + a = Prealloc; + } s = 0; - a = aalloc; if (QTypeInfo::isStatic) { QT_TRY { // copy all the old elements