1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
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-09-09 23:57:20 +02:00
2021-08-08 17:25:57 +01:00
2010-08-07 20:25:17 +02:00
2020-06-07 15:51:03 +04:00
2021-04-30 20:49:22 +02:00
2021-10-23 10:31:46 +02:00
2021-04-11 14:46:51 +02:00
2021-10-20 23:02:15 +02:00
2021-10-20 23:02:15 +02:00
2019-02-23 08:02:12 +04:00
2021-10-10 13:13:57 +02:00
2020-03-14 09:38:24 +01:00
2015-04-21 23:40:10 +02:00
2020-03-14 09:38:24 +01:00
2021-08-15 19:50:28 +02:00
2021-10-13 10:08:28 +00:00
2021-08-04 17:49:57 -07:00
2021-08-04 17:49:57 -07:00