summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-02-01 21:21:22 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-02-02 22:22:29 +0000
commit9b14f1cc212f6b67fd6c3dd01c8455e4cdce2b29 (patch)
treeffcba6918ca280fd844f7184aa39ee7ea0326406 /src
parent9cd5c614559159fe09b414d568f88a192405b84d (diff)
QLayoutEngine: replace an inefficient QList with QVarLengthArray
QList<int> wastes 50% space on 64-bit platforms. Use a more fitting container. Since the storage is only used temporarily, try to allocate it on the stack with QVarLengthArray. Also give it better name than just 'list'. Change-Id: I3dfb1d5927ac36f4b352b5d91ce0c9401b20705e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/kernel/qlayoutengine.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/widgets/kernel/qlayoutengine.cpp b/src/widgets/kernel/qlayoutengine.cpp
index a134d3a3ef..d0d4df8e1e 100644
--- a/src/widgets/kernel/qlayoutengine.cpp
+++ b/src/widgets/kernel/qlayoutengine.cpp
@@ -37,7 +37,7 @@
#include "qvector.h"
#include "qwidget.h"
-#include <qlist.h>
+#include <qvarlengtharray.h>
#include <qdebug.h>
#include <algorithm>
@@ -121,12 +121,13 @@ void qGeomCalc(QVector<QLayoutStruct> &chain, int start, int count,
sumSpacing = spacer * spacerCount;
}
- QList<int> list;
+ QVarLengthArray<int, 32> minimumSizes;
+ minimumSizes.reserve(count);
for (i = start; i < start + count; i++)
- list << chain.at(i).minimumSize;
+ minimumSizes << chain.at(i).minimumSize;
- std::sort(list.begin(), list.end());
+ std::sort(minimumSizes.begin(), minimumSizes.end());
int space_left = space - sumSpacing;
@@ -135,7 +136,7 @@ void qGeomCalc(QVector<QLayoutStruct> &chain, int start, int count,
int space_used=0;
int current = 0;
while (idx < count && space_used < space_left) {
- current = list.at(idx);
+ current = minimumSizes.at(idx);
space_used = sum + current * (count - idx);
sum += current;
++idx;