mirror of
https://github.com/OpenMW/openmw.git
synced 2025-10-25 02:26:42 +00:00
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. |
||
|---|---|---|
| .. | ||
| algorithm.hpp | ||
| barrier.hpp | ||
| budgetmeasurement.hpp | ||
| compression.cpp | ||
| compression.hpp | ||
| constants.hpp | ||
| convert.hpp | ||
| coordinateconverter.hpp | ||
| endianness.hpp | ||
| frameratelimiter.hpp | ||
| guarded.hpp | ||
| hash.hpp | ||
| helpviewer.cpp | ||
| helpviewer.hpp | ||
| mathutil.hpp | ||
| messageformatparser.cpp | ||
| messageformatparser.hpp | ||
| objectpool.hpp | ||
| pathhelpers.hpp | ||
| progressreporter.hpp | ||
| resourcehelpers.cpp | ||
| resourcehelpers.hpp | ||
| rng.cpp | ||
| rng.hpp | ||
| stringops.hpp | ||
| thread.cpp | ||
| thread.hpp | ||
| timer.hpp | ||
| utf8stream.hpp | ||
| weakcache.hpp | ||