From e7b0470f5506dcb37753ec4465ca3bb14260163a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 26 Oct 2019 21:14:43 -0400 Subject: [PATCH] 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. --- Runtime/Character/CCharLayoutInfo.cpp | 6 ++++-- Runtime/Character/CCharLayoutInfo.hpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Runtime/Character/CCharLayoutInfo.cpp b/Runtime/Character/CCharLayoutInfo.cpp index 2e0a8b610..3273e6917 100644 --- a/Runtime/Character/CCharLayoutInfo.cpp +++ b/Runtime/Character/CCharLayoutInfo.cpp @@ -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; } diff --git a/Runtime/Character/CCharLayoutInfo.hpp b/Runtime/Character/CCharLayoutInfo.hpp index 9ec09cf3c..7e0ee2172 100644 --- a/Runtime/Character/CCharLayoutInfo.hpp +++ b/Runtime/Character/CCharLayoutInfo.hpp @@ -35,7 +35,7 @@ public: class CCharLayoutInfo { std::shared_ptr x0_node; CSegIdList x8_segIdList; - std::map x18_segIdMap; + std::map> x18_segIdMap; public: CCharLayoutInfo(CInputStream& in);