Skip to content
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 29 commits into from
Nov 18, 2019
Merged

Conversation

BevapDin
Copy link
Contributor

SUMMARY: None

Instead of looking up pathes within the FILENAMES map they are now accessible via functions.

This avoids some potential problems:

  • FILENAMES is globally accessible, everyone can write into it directly.
  • The key can be misspelled without anyone noticing it (see the commits regarding unused entries within the map).

@ifreund ifreund added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Nov 17, 2019
{
const std::string base_path = FILENAMES[pathid];
const std::string base_path = path;
Copy link
Contributor

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants