Skip to content

Codefix: Earlier return from window functions which use window number.#14960

Merged
LordAro merged 1 commit intoOpenTTD:masterfrom
Rito13:Fix_company_invalidate_by_id
Dec 31, 2025
Merged

Codefix: Earlier return from window functions which use window number.#14960
LordAro merged 1 commit intoOpenTTD:masterfrom
Rito13:Fix_company_invalidate_by_id

Conversation

@Rito13
Copy link
Contributor

@Rito13 Rito13 commented Dec 22, 2025

Motivation / Problem

The code for invalidating window data by class is faster than the one for invalidating by window number.

void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
{
	for (Window *w : Window::Iterate()) {
		if (w->window_class == cls) {
			w->InvalidateData(data, gui_scope);
		}
	}
}

void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
{
	for (Window *w : Window::Iterate()) {
		if (w->window_class == cls && w->window_number == number) {
			w->InvalidateData(data, gui_scope);
		}
	}
}

Description

As window numbers are unique within a window class, it is not necessary to look for another window with the same class and number, so simply return.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@PeterN
Copy link
Member

PeterN commented Dec 24, 2025

"Speed up" is quite the claim. But using an early return is none-the-less not a bad idea.

@Rito13 Rito13 changed the title Codefix: Speed up window functions which use window number. Codefix: Earlier return from window functions which use window number. Dec 27, 2025
@Rito13 Rito13 force-pushed the Fix_company_invalidate_by_id branch from 52e1dd1 to 31ee7c0 Compare December 27, 2025 19:14
@Rito13 Rito13 force-pushed the Fix_company_invalidate_by_id branch from 31ee7c0 to e155046 Compare December 30, 2025 13:15
@LordAro LordAro merged commit 29a26b7 into OpenTTD:master Dec 31, 2025
16 checks passed
@Rito13 Rito13 deleted the Fix_company_invalidate_by_id branch January 3, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants