CCharLayoutInfo: Use heterogenous lookup with std::map

Allows using std::string_view with std::map without the need to
construct a completely new std::string instance. Making the lookups via
GetSegIdFromString() completely non-allocating.

Notably, this also allows it to properly function with
non-null-terminated string_view instances.
This commit is contained in:
Lioncash 2019-10-26 21:14:43 -04:00
parent 18382e5bb6
commit e7b0470f55
2 changed files with 5 additions and 3 deletions

View File

@ -19,9 +19,11 @@ zeus::CVector3f CCharLayoutInfo::GetFromRootUnrotated(const CSegId& id) const {
}
CSegId CCharLayoutInfo::GetSegIdFromString(std::string_view name) const {
auto it = x18_segIdMap.find(name.data());
if (it == x18_segIdMap.end())
const auto it = x18_segIdMap.find(name);
if (it == x18_segIdMap.cend()) {
return {};
}
return it->second;
}

View File

@ -35,7 +35,7 @@ public:
class CCharLayoutInfo {
std::shared_ptr<CCharLayoutNode> x0_node;
CSegIdList x8_segIdList;
std::map<std::string, CSegId> x18_segIdMap;
std::map<std::string, CSegId, std::less<>> x18_segIdMap;
public:
CCharLayoutInfo(CInputStream& in);