qstylesheet: remove a few unneeded memory allocations

One foreach too many, creating a temporary container.
Converted to range-loop, as drive-by change.

Change-Id: Ie2bb94a7147edcfc0d8b5f479604f5ebe113d7cb
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Sergio Martins 2018-01-12 18:03:27 +00:00 committed by Sérgio Martins
parent f40cc95d05
commit e459130e70

View File

@ -2692,24 +2692,19 @@ void QStyleSheetStyle::unsetStyleSheetFont(QWidget *w) const
static void updateObjects(const QList<const QObject *>& objects) static void updateObjects(const QList<const QObject *>& objects)
{ {
if (!styleSheetCaches->styleRulesCache.isEmpty() || !styleSheetCaches->hasStyleRuleCache.isEmpty() || !styleSheetCaches->renderRulesCache.isEmpty()) { if (!styleSheetCaches->styleRulesCache.isEmpty() || !styleSheetCaches->hasStyleRuleCache.isEmpty() || !styleSheetCaches->renderRulesCache.isEmpty()) {
for (int i = 0; i < objects.size(); ++i) { for (const QObject *object : objects) {
const QObject *object = objects.at(i);
styleSheetCaches->styleRulesCache.remove(object); styleSheetCaches->styleRulesCache.remove(object);
styleSheetCaches->hasStyleRuleCache.remove(object); styleSheetCaches->hasStyleRuleCache.remove(object);
styleSheetCaches->renderRulesCache.remove(object); styleSheetCaches->renderRulesCache.remove(object);
} }
} }
QWidgetList widgets;
foreach (const QObject *object, objects) {
if (QWidget *w = qobject_cast<QWidget*>(const_cast<QObject*>(object)))
widgets << w;
}
QEvent event(QEvent::StyleChange); QEvent event(QEvent::StyleChange);
foreach (QWidget *widget, widgets) { for (const QObject *object : objects) {
widget->style()->polish(widget); if (auto widget = qobject_cast<QWidget*>(const_cast<QObject*>(object))) {
QApplication::sendEvent(widget, &event); widget->style()->polish(widget);
QApplication::sendEvent(widget, &event);
}
} }
} }