Optimize get_dangerous_tile, also is_ and prompt_ #76950
Merged
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.
Summary
Performance "Reduce unnecessary/duplicate checks for dangerous tiles"
Purpose of change
Dangerous tile checking currently runs the same checks multiple times, and enumerates more dangers than necessary in some cases.
Describe the solution
Add a parameter to
get_dangerous_tile
for the max number of dangers to return, and use that parameter inis_dangerous_tile
which doesn't care if there's more than one.Add a parameter to
prompt_dangerous_tile
to provide the list of dangers if it's already available.Describe alternatives you've considered
I thought about trying to use an optional wrapped reference instead of a pointer for
harmful_stuff
but my efforts were significantly less readable.Testing
I created some fields and traps and moved around them to produce various prompts.
Additional context