From 9b14f1cc212f6b67fd6c3dd01c8455e4cdce2b29 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 1 Feb 2015 21:21:22 +0100 Subject: QLayoutEngine: replace an inefficient QList with QVarLengthArray MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QList 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 Reviewed-by: Jan Arve Sæther --- src/widgets/kernel/qlayoutengine.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') 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 +#include #include #include @@ -121,12 +121,13 @@ void qGeomCalc(QVector &chain, int start, int count, sumSpacing = spacer * spacerCount; } - QList list; + QVarLengthArray 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 &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; -- cgit v1.2.3