mirror of
https://github.com/OpenMW/openmw.git
synced 2026-01-02 15:13:06 +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. |
||
|---|---|---|
| .. | ||
| bsa | ||
| bullethelpers | ||
| compiler | ||
| config | ||
| contentselector | ||
| crashcatcher | ||
| debug | ||
| detournavigator | ||
| esm | ||
| esmloader | ||
| esmterrain | ||
| fallback | ||
| files | ||
| fontloader | ||
| interpreter | ||
| loadinglistener | ||
| lua | ||
| misc | ||
| myguiplatform | ||
| nif | ||
| nifbullet | ||
| nifosg | ||
| process | ||
| queries | ||
| resource | ||
| sceneutil | ||
| sdlutil | ||
| settings | ||
| shader | ||
| sqlite3 | ||
| terrain | ||
| to_utf8 | ||
| translation | ||
| version | ||
| vfs | ||
| widgets | ||
| CMakeLists.txt | ||
| doc.hpp | ||