1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00
OpenMW/components
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
..
2021-10-14 14:46:44 +02:00
2021-05-12 10:34:39 +04:00
2021-10-17 19:55:29 +02:00
2021-10-05 22:51:12 +02:00
2021-07-27 07:58:57 +03:00
2021-10-06 10:04:03 +00:00
2019-02-23 08:02:12 +04:00
2021-10-23 10:31:46 +02:00
2021-10-21 19:48:31 +02:00
2018-10-09 10:21:12 +04:00
2021-10-14 14:46:44 +02:00
2021-08-15 19:50:28 +02:00