1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-12 17:43:05 +00:00
openmw/apps
Bo Svensson 7f9beac3a7
refactors a case insensitive map (#3184)
This PR aims to spark the retirement of a questionable pattern I have found all over our code base. I will illustrate how this pattern encourages code duplication, lacks type safety, requires documentation and can be prone to bugs.
```
std::map<std::string, Object> mMap; // Stored in all lowercase for a case-insensitive lookup

std::string lowerKey = Misc::StringUtils::lowerCase(key);
mMap.emplace(lowerKey, object);

std::string lowerKey = Misc::StringUtils::lowerCase(key);
mMap.find(lowerKey);

mMap.find(key); // Not found. Oops!
```
An alternative approach produces no such issues.
```
std::unordered_map<std::string, Object, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual> mMap;

mMap.emplace(key, object);

mMap.find(key);
```
Of course, such an alternative will work for a `map` as well, but an `unordered_map` is generally preferable over a `map` with these changes because we have moved `lowerCase` into the comparison operator. 

In this PR I have refactored `Animation::mNodeMap` accordingly. I have reviewed and adapted all direct and indirect usage of `Animation::mNodeMap` to ensure we do not change behaviour with this PR.
2021-10-25 09:18:26 +02:00
..
benchmarks Store heightfields as array of heights instead of triangles 2021-07-26 00:22:21 +02:00
bsatool cleans up BSAFile (#3177) 2021-10-14 14:46:44 +02:00
esmtool Do not use union to access FIXED_STRING<4> as int 2021-10-17 17:16:21 +02:00
essimporter Do not use union to access FIXED_STRING<4> as int 2021-10-17 17:16:21 +02:00
launcher Do not use union to access FIXED_STRING<4> as int 2021-10-17 17:16:21 +02:00
mwiniimporter Using auto keyword in most apps 2021-05-18 19:20:59 -05:00
niftest Use recurse subdirectory iterator to iterate over the VFS without exposing internal details 2021-09-14 18:09:54 +02:00
opencs fixes a crash (#3183) 2021-10-23 10:31:46 +02:00
openmw refactors a case insensitive map (#3184) 2021-10-25 09:18:26 +02:00
openmw_test_suite Merge branch 'fix_windows_tests' into 'master' 2021-10-22 12:35:10 +00:00
wizard Remove 'no relevant classes' moc warning 2021-09-14 11:20:18 +02:00
doc.hpp