Codechange: Use locals for company/deity mode during loops. #11686
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
Script methods that build lists with ownership checks call
ScriptObject::GetCompany()
and/orScriptCopmanyMode::IsDeity()
for every iteration.While individually these are not very expensive, the cost adds up.
Description
Instead, store the value of these calls in local variables before iterating the loops. This gives a reasonable benefit with large games and heavy scripts, though of course in practice results vary.
This is the result using Xarick's corona gs save from #10548:
Limitations
This is related to but conflicts with #11676. I'm made this a separate PR as it has wider scope and the changes are a bit more straightforward.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.