QVarLengthArray: use memory on stack if possible
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>
This commit is contained in:
parent
a47f21edd6
commit
47b99599e8
@ -252,12 +252,17 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(int asize, int 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;
|
||||
}
|
||||
s = 0;
|
||||
a = aalloc;
|
||||
if (QTypeInfo<T>::isStatic) {
|
||||
QT_TRY {
|
||||
// copy all the old elements
|
||||
|
Loading…
x
Reference in New Issue
Block a user