summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorPeter Kümmel <syntheticpp@gmx.net>2012-10-09 16:52:37 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-11 02:47:52 +0200
commit47b99599e8676f42234a39a81b07ee06462a2e3a (patch)
treea5af429ccf3d095a24470e8d0ab4986e9530dc50 /src/corelib
parenta47f21edd61ce033475743a35d6dad35f2e68c48 (diff)
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>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qvarlengtharray.h15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 90b10a3ed1..0c5b61d68a 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -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