summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-08-17 20:44:39 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-07-17 18:22:16 +0000
commit70d84f26bdd35f03ccd6220e3736896fede20c89 (patch)
tree488d538e22ea1c592a72ea76fed0ff0992b258ad /src/widgets
parent7c46a96972100097daeae2e47cbb1b81d5541e04 (diff)
QStyleSheetStyle: don't hold ButtonInfo in QList
ButtonInfo is larger than a void*, so holding them in a QList is needlessly inefficient. Worse, the code could come to depend on the fragile property of (inefficient) QLists that references to elements therein never are invalidated. Fix by holding it in QVector. Also reserve() the vector, even though we can't tell the size exectly. It's a short-lived vector. When appending, add an optimistic qMove(). I would have liked to use std::vector instead, but QRenderRule, thus ButtonInfo, isn't nothrow-move-constructible, because of missing move constructors on QBrush and QFont, among others. Change-Id: I89164f4ed5745498093102f022a7ef32186e8045 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index bf06ebdc1c..662e1f9b96 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -746,8 +746,10 @@ QHash<QStyle::SubControl, QRect> QStyleSheetStyle::titleBarLayout(const QWidget
int offsets[3] = { 0, 0, 0 };
enum Where { Left, Right, Center, NoWhere } where = Left;
- QList<ButtonInfo> infos;
- for (int i = 0; i < layout.count(); i++) {
+ QVector<ButtonInfo> infos;
+ const int numLayouts = layout.size();
+ infos.reserve(numLayouts);
+ for (int i = 0; i < numLayouts; i++) {
const int element = layout[i].toInt();
if (element == '(') {
where = Center;
@@ -801,14 +803,14 @@ QHash<QStyle::SubControl, QRect> QStyleSheetStyle::titleBarLayout(const QWidget
info.rule = subRule;
info.offset = offsets[where];
info.where = where;
- infos.append(info);
+ infos.append(qMove(info));
offsets[where] += info.width;
}
}
- for (int i = 0; i < infos.count(); i++) {
- ButtonInfo info = infos[i];
+ for (int i = 0; i < infos.size(); i++) {
+ const ButtonInfo &info = infos[i];
QRect lr = cr;
switch (info.where) {
case Center: {