Micro-optimize QApplication.

Avoid repeated instantiation of end() in loops, use variable instead.

Change-Id: I5f58fa63c2845827ebe9be2d0fcee80b7ccc74bc
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Friedemann Kleint 2015-02-19 13:51:46 +01:00
parent 4725cbad26
commit 3f84c18ac0

View File

@ -827,7 +827,7 @@ QApplication::~QApplication()
if (QWidgetPrivate::allWidgets) { if (QWidgetPrivate::allWidgets) {
QWidgetSet *mySet = QWidgetPrivate::allWidgets; QWidgetSet *mySet = QWidgetPrivate::allWidgets;
QWidgetPrivate::allWidgets = 0; QWidgetPrivate::allWidgets = 0;
for (QWidgetSet::ConstIterator it = mySet->constBegin(); it != mySet->constEnd(); ++it) { for (QWidgetSet::ConstIterator it = mySet->constBegin(), cend = mySet->constEnd(); it != cend; ++it) {
QWidget *w = *it; QWidget *w = *it;
if (!w->parent()) // window if (!w->parent()) // window
w->destroy(true, true); w->destroy(true, true);
@ -1190,7 +1190,7 @@ void QApplication::setStyle(QStyle *style)
// clean up the old style // clean up the old style
if (QApplicationPrivate::app_style) { if (QApplicationPrivate::app_style) {
if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
QWidget *w = *it; QWidget *w = *it;
if (!(w->windowType() == Qt::Desktop) && // except desktop if (!(w->windowType() == Qt::Desktop) && // except desktop
w->testAttribute(Qt::WA_WState_Polished)) { // has been polished w->testAttribute(Qt::WA_WState_Polished)) { // has been polished
@ -1238,8 +1238,8 @@ void QApplication::setStyle(QStyle *style)
// re-polish existing widgets if necessary // re-polish existing widgets if necessary
if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
for (QWidgetList::ConstIterator it1 = all.constBegin(); it1 != all.constEnd(); ++it1) { for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
QWidget *w = *it1; QWidget *w = *it;
if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) { if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) {
if (w->style() == QApplicationPrivate::app_style) if (w->style() == QApplicationPrivate::app_style)
QApplicationPrivate::app_style->polish(w); // repolish QApplicationPrivate::app_style->polish(w); // repolish
@ -1250,8 +1250,8 @@ void QApplication::setStyle(QStyle *style)
} }
} }
for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++it2) { for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
QWidget *w = *it2; QWidget *w = *it;
if (w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_SetStyle)) { if (w->windowType() != Qt::Desktop && !w->testAttribute(Qt::WA_SetStyle)) {
QEvent e(QEvent::StyleChange); QEvent e(QEvent::StyleChange);
QApplication::sendEvent(w, &e); QApplication::sendEvent(w, &e);
@ -1416,12 +1416,15 @@ void QApplication::setGlobalStrut(const QSize& strut)
*/ */
QPalette QApplication::palette(const QWidget* w) QPalette QApplication::palette(const QWidget* w)
{ {
typedef PaletteHash::const_iterator PaletteHashConstIt;
PaletteHash *hash = app_palettes(); PaletteHash *hash = app_palettes();
if (w && hash && hash->size()) { if (w && hash && hash->size()) {
QHash<QByteArray, QPalette>::ConstIterator it = hash->constFind(w->metaObject()->className()); PaletteHashConstIt it = hash->constFind(w->metaObject()->className());
if (it != hash->constEnd()) const PaletteHashConstIt cend = hash->constEnd();
if (it != cend)
return *it; return *it;
for (it = hash->constBegin(); it != hash->constEnd(); ++it) { for (it = hash->constBegin(); it != cend; ++it) {
if (w->inherits(it.key())) if (w->inherits(it.key()))
return it.value(); return it.value();
} }
@ -1480,7 +1483,7 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char*
QApplication::sendEvent(QApplication::instance(), &e); QApplication::sendEvent(QApplication::instance(), &e);
QWidgetList wids = QApplication::allWidgets(); QWidgetList wids = QApplication::allWidgets();
for (QWidgetList::ConstIterator it = wids.constBegin(); it != wids.constEnd(); ++it) { for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) {
QWidget *w = *it; QWidget *w = *it;
if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class
QApplication::sendEvent(w, &e); QApplication::sendEvent(w, &e);
@ -1582,6 +1585,8 @@ QFont QApplication::font()
QFont QApplication::font(const QWidget *widget) QFont QApplication::font(const QWidget *widget)
{ {
typedef FontHash::const_iterator FontHashConstIt;
FontHash *hash = app_fonts(); FontHash *hash = app_fonts();
if (widget && hash && hash->size()) { if (widget && hash && hash->size()) {
@ -1593,11 +1598,11 @@ QFont QApplication::font(const QWidget *widget)
return hash->value(QByteArrayLiteral("QMiniFont")); return hash->value(QByteArrayLiteral("QMiniFont"));
} }
#endif #endif
QHash<QByteArray, QFont>::ConstIterator it = FontHashConstIt it = hash->constFind(widget->metaObject()->className());
hash->constFind(widget->metaObject()->className()); const FontHashConstIt cend = hash->constEnd();
if (it != hash->constEnd()) if (it != cend)
return it.value(); return it.value();
for (it = hash->constBegin(); it != hash->constEnd(); ++it) { for (it = hash->constBegin(); it != cend; ++it) {
if (widget->inherits(it.key())) if (widget->inherits(it.key()))
return it.value(); return it.value();
} }
@ -1662,7 +1667,7 @@ void QApplication::setFont(const QFont &font, const char *className)
QApplication::sendEvent(QApplication::instance(), &e); QApplication::sendEvent(QApplication::instance(), &e);
QWidgetList wids = QApplication::allWidgets(); QWidgetList wids = QApplication::allWidgets();
for (QWidgetList::ConstIterator it = wids.constBegin(); it != wids.constEnd(); ++it) { for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) {
QWidget *w = *it; QWidget *w = *it;
if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class
sendEvent(w, &e); sendEvent(w, &e);
@ -1767,7 +1772,7 @@ QWidgetList QApplication::topLevelWidgets()
QWidgetList list; QWidgetList list;
QWidgetList all = allWidgets(); QWidgetList all = allWidgets();
for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) {
QWidget *w = *it; QWidget *w = *it;
if (w->isWindow() && w->windowType() != Qt::Desktop) if (w->isWindow() && w->windowType() != Qt::Desktop)
list.append(w); list.append(w);