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>
bb10
Marc Mutz 2015-02-01 21:21:22 +01:00
parent 9cd5c61455
commit 9b14f1cc21
1 changed files with 6 additions and 5 deletions

View File

@ -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;