1
0
Fork 0

Cleanup: remove unneeded labels and gotos.

The window list supports deletion of arbitrary windows, while iterating over it.
pull/9261/head
frosch 2021-05-09 16:20:38 +02:00 committed by frosch
parent ba193f2e23
commit 95abdfdef9
1 changed files with 5 additions and 25 deletions

View File

@ -1168,14 +1168,10 @@ void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
*/ */
void DeleteWindowByClass(WindowClass cls) void DeleteWindowByClass(WindowClass cls)
{ {
restart_search: /* Note: the container remains stable, even when deleting windows. */
/* 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 */
for (Window *w : Window::IterateFromBack()) { for (Window *w : Window::IterateFromBack()) {
if (w->window_class == cls) { if (w->window_class == cls) {
delete w; delete w;
goto restart_search;
} }
} }
} }
@ -1188,14 +1184,10 @@ restart_search:
*/ */
void DeleteCompanyWindows(CompanyID id) void DeleteCompanyWindows(CompanyID id)
{ {
restart_search: /* Note: the container remains stable, even when deleting windows. */
/* 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 */
for (Window *w : Window::IterateFromBack()) { for (Window *w : Window::IterateFromBack()) {
if (w->owner == id) { if (w->owner == id) {
delete w; delete w;
goto restart_search;
} }
} }
@ -3325,10 +3317,7 @@ void CallWindowGameTickEvent()
*/ */
void DeleteNonVitalWindows() void DeleteNonVitalWindows()
{ {
restart_search: /* Note: the container remains stable, even when deleting windows. */
/* 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 */
for (const Window *w : Window::IterateFromBack()) { for (const Window *w : Window::IterateFromBack()) {
if (w->window_class != WC_MAIN_WINDOW && if (w->window_class != WC_MAIN_WINDOW &&
w->window_class != WC_SELECT_GAME && w->window_class != WC_SELECT_GAME &&
@ -3338,7 +3327,6 @@ restart_search:
(w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned' (w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
delete w; delete w;
goto restart_search;
} }
} }
} }
@ -3355,14 +3343,10 @@ void DeleteAllNonVitalWindows()
/* Delete every window except for stickied ones, then sticky ones as well */ /* Delete every window except for stickied ones, then sticky ones as well */
DeleteNonVitalWindows(); DeleteNonVitalWindows();
restart_search: /* Note: the container remains stable, even when deleting windows. */
/* 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 */
for (const Window *w : Window::IterateFromBack()) { for (const Window *w : Window::IterateFromBack()) {
if (w->flags & WF_STICKY) { if (w->flags & WF_STICKY) {
delete w; delete w;
goto restart_search;
} }
} }
} }
@ -3384,14 +3368,10 @@ void DeleteAllMessages()
*/ */
void DeleteConstructionWindows() void DeleteConstructionWindows()
{ {
restart_search: /* Note: the container remains stable, even when deleting windows. */
/* 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 */
for (const Window *w : Window::IterateFromBack()) { for (const Window *w : Window::IterateFromBack()) {
if (w->window_desc->flags & WDF_CONSTRUCTION) { if (w->window_desc->flags & WDF_CONSTRUCTION) {
delete w; delete w;
goto restart_search;
} }
} }