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>
This commit is contained in:
parent
7c46a96972
commit
70d84f26bd
@ -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: {
|
||||
|
Loading…
Reference in New Issue
Block a user