QApplication: replace some sneaky code with a strategic goto

Instead of replacing the container iterated over, in the middle
of the loop body(!), place a label in front of the loop and
use goto to restart the entire loop.

This allows to mark the variable 'list' const, which is a
prerequesite for replacing the loop with a C++11 range-for
one.

But it also makes the code less cryptic. No-one expects the
container to be re-seated in the middle of the loop.

The compiler agrees: saves 144b of text size on optimized
AMD64 GCC 4.9 Linux builds.

Change-Id: I22d07672a1bbe9d7ffb083ae231eda760c29d350
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-11-30 11:03:29 +01:00 committed by Simon Hausmann
parent 1264c22b86
commit bc6d677b7e

View File

@ -1905,6 +1905,7 @@ bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows
processedWindows->append(window);
}
retry:
QWidgetList list = QApplication::topLevelWidgets();
for (int i = 0; i < list.size(); ++i) {
QWidget *w = list.at(i);
@ -1915,8 +1916,7 @@ bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows
return false;
if (window)
processedWindows->append(window);
list = QApplication::topLevelWidgets();
i = -1;
goto retry;
}
}
return true;