summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2021-05-09 16:20:38 +0200
committerfrosch <github@elsenhans.name>2021-05-12 23:22:41 +0200
commit95abdfdef9c9c79e79cb3f32bc54aec66e224d7e (patch)
tree69111d878757efd9924417b2bb4977dc02fa2ae0
parentba193f2e23ce82cdfca37771147848751c6993e1 (diff)
downloadopenttd-95abdfdef9c9c79e79cb3f32bc54aec66e224d7e.tar.xz
Cleanup: remove unneeded labels and gotos.
The window list supports deletion of arbitrary windows, while iterating over it.
-rw-r--r--src/window.cpp30
1 files changed, 5 insertions, 25 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 3fcda7d42..d6901bd97 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1168,14 +1168,10 @@ void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
*/
void DeleteWindowByClass(WindowClass cls)
{
-restart_search:
- /* When we find the window to delete, we need to restart the search
- * as deleting this window could cascade in deleting (many) others
- * anywhere in the z-array */
+ /* Note: the container remains stable, even when deleting windows. */
for (Window *w : Window::IterateFromBack()) {
if (w->window_class == cls) {
delete w;
- goto restart_search;
}
}
}
@@ -1188,14 +1184,10 @@ restart_search:
*/
void DeleteCompanyWindows(CompanyID id)
{
-restart_search:
- /* When we find the window to delete, we need to restart the search
- * as deleting this window could cascade in deleting (many) others
- * anywhere in the z-array */
+ /* Note: the container remains stable, even when deleting windows. */
for (Window *w : Window::IterateFromBack()) {
if (w->owner == id) {
delete w;
- goto restart_search;
}
}
@@ -3325,10 +3317,7 @@ void CallWindowGameTickEvent()
*/
void DeleteNonVitalWindows()
{
-restart_search:
- /* When we find the window to delete, we need to restart the search
- * as deleting this window could cascade in deleting (many) others
- * anywhere in the z-array */
+ /* Note: the container remains stable, even when deleting windows. */
for (const Window *w : Window::IterateFromBack()) {
if (w->window_class != WC_MAIN_WINDOW &&
w->window_class != WC_SELECT_GAME &&
@@ -3338,7 +3327,6 @@ restart_search:
(w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
delete w;
- goto restart_search;
}
}
}
@@ -3355,14 +3343,10 @@ void DeleteAllNonVitalWindows()
/* Delete every window except for stickied ones, then sticky ones as well */
DeleteNonVitalWindows();
-restart_search:
- /* When we find the window to delete, we need to restart the search
- * as deleting this window could cascade in deleting (many) others
- * anywhere in the z-array */
+ /* Note: the container remains stable, even when deleting windows. */
for (const Window *w : Window::IterateFromBack()) {
if (w->flags & WF_STICKY) {
delete w;
- goto restart_search;
}
}
}
@@ -3384,14 +3368,10 @@ void DeleteAllMessages()
*/
void DeleteConstructionWindows()
{
-restart_search:
- /* When we find the window to delete, we need to restart the search
- * as deleting this window could cascade in deleting (many) others
- * anywhere in the z-array */
+ /* Note: the container remains stable, even when deleting windows. */
for (const Window *w : Window::IterateFromBack()) {
if (w->window_desc->flags & WDF_CONSTRUCTION) {
delete w;
- goto restart_search;
}
}