-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce enum bitset and use it for monster flags and triggers #29368
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Jenkins rebuild |
codemime
force-pushed
the
enum-bitset-mon
branch
2 times, most recently
from
April 7, 2019 21:08
6092cc1
to
6088811
Compare
ifreund
reviewed
Apr 7, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good to me, just found one typo.
ifreund
added
[C++]
Changes (can be) made in C++. Previously named `Code`
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
Monsters
Monsters both friendly and unfriendly.
labels
Apr 7, 2019
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[C++]
Changes (can be) made in C++. Previously named `Code`
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
Monsters
Monsters both friendly and unfriendly.
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: Infrastructure "Introduce enum bitset and use it for monster flags and triggers"
Purpose of change
Monster flags/triggers were effectively duplicated in the
mtype
class: each stored as bothstd::set
andstd::bitset
ofenum
entries. There's no point keeping around duplicated data and spend resources for maintaining its consistency, so only bitsets survived: a little benchmark showed thatstd::bitset
is ten times faster thanstd::set
for the purpose of accessing flags. However, plain bitsets aren't perfect for this either: they lack type-safety just like plainenum
s do.Describe the solution
enum_bitset
for the purpose of handlingenum class
-based flag entries in a type-safe manner (essentially it's a wrapper aroundstd::bitset
), and applied it initially to monster flags/behavioral triggers;set
s and string accessors inmtype
: working with string identifiers is error-prone due to typos, can be potentially slower, so it should be discouraged;mtype
;string-to-enum
maps into static constants (they were member variables);enum class
. Didn't bother with convertingflags
, mostly out of laziness, but also to prevent oversizing the PR;Describe alternatives you've considered
Leave everything as it is.
Additional context
Shoudn't introduce any changes in observable behavior.