From 70d84f26bdd35f03ccd6220e3736896fede20c89 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 17 Aug 2014 20:44:39 +0200 Subject: [PATCH] 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 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/styles/qstylesheetstyle.cpp | 12 +++++++----- 1 file 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 QStyleSheetStyle::titleBarLayout(const QWidget int offsets[3] = { 0, 0, 0 }; enum Where { Left, Right, Center, NoWhere } where = Left; - QList infos; - for (int i = 0; i < layout.count(); i++) { + QVector 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 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: {