-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Replace FILENAMES map lookup with functions: #35570
Merged
Merged
+519
−328
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
ifreund
reviewed
Nov 17, 2019
src/path_info.cpp
Outdated
{ | ||
const std::string base_path = FILENAMES[pathid]; | ||
const std::string base_path = path; |
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.
clang tidy is complaining about this not being a reference. Seems to me that we don't even need the variable though, how about just changing the name of the parameter to base_path
?
The value for key "recycledir" is never read, so it does not need to exist within the map.
An entry with key "gfx" is never set, so it will always yield an empty string. So this replaces that pointless lookup with an empty string directly.
An entry with key "legacy_fontlist" is never created, the lookup for it will yield an empty string. Open an empty path will always fail, so the then-block is never run. Therefor this removes that dead code completely.
Instead the caller has to do this now. Changed the names of the parameters accordingly as they are no labels anymore.
…soundpack_from to take actual paths Not just keys into the FILENAMES map. Overall behaviour is not changed, the caller of those functions now does the lookup in the `FILENAMES` map.
Access it only via functions from the header. All function names are the names of the key they look up in the `FILENAMES` map, so the information to the reader is exactly the same.
Instead of storing them in the map, calculate them when needed. Removes the useless compile time check for `SDL_SOUND` / `TILES`: the values are always available, even when they are not used (in builds without sound/tiles). Adding the functions does not significantly increase the size of the application.
This also allows the function to be static and private within the cpp file.
…e cpp file. This also allows to make the called functions private within the cpp file.
…up keys So instead of doing the map lookup, the caller does it now.
It's not used by anything anymore.
It is only called from one place anyway.
It is only called from one place only.
…-String Also: make it non-optional: there is only one place where it was called without arguments, and that code can easily call it with an empty string explicitly.
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
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: None
Instead of looking up pathes within the FILENAMES map they are now accessible via functions.
This avoids some potential problems: