From bc6d677b7e9c7809af68d8bcbd3a5793903c4c98 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 30 Nov 2015 11:03:29 +0100 Subject: 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) --- src/widgets/kernel/qapplication.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 6fffe33ce8..4510fc85b6 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -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; -- cgit v1.2.3