Trivial: minor speedup of monster->Character attitude calculation #45421
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
SUMMARY: Performance "Minor speedup monster->Character attitude calculation"
Purpose of change
Currently
monster::attitude( const Character *u )
requests and iteratesCharacter
mutation list twice.This may waste some CPU cycles when player has lots of mutations or there are lots of NPCs around.
Describe the solution
Request character mutation list only once.
Describe alternatives you've considered
Use "observer"-like pattern to iterate character mutations without construction of the vector. However, in this case it might be an overkill, as usually characters don't have too many mutations.
Testing
Checked that game compiles and loads.
Additional context
Before:
![image](https://user-images.githubusercontent.com/2865203/99159867-995e2a80-2695-11eb-9455-2d587655934f.png)
After:
![image](https://user-images.githubusercontent.com/2865203/99159871-ad099100-2695-11eb-8b2d-d0c4a9ab81a1.png)