2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-10 06:27:43 +00:00

CAiFuncMap: Store std::string_view instances instead of std::string

We only make use of static string entries, so we can make use of
std::string view to elide several memory allocations.
This commit is contained in:
Lioncash
2020-05-08 16:33:29 -04:00
parent a9be7b45b2
commit a0c4b6b3ec
5 changed files with 18 additions and 18 deletions

View File

@@ -14,7 +14,7 @@ CStateMachine::CStateMachine(CInputStream& in) {
for (u32 i = 0; i < stateCount; ++i) {
std::string name = in.readString(31, false);
CAiStateFunc func = CAi::GetStateFunc(name.c_str());
CAiStateFunc func = CAi::GetStateFunc(name);
x0_states.emplace_back(func, name.c_str());
}
@@ -28,14 +28,14 @@ CStateMachine::CStateMachine(CInputStream& in) {
x0_states[i].SetTriggers(firstTrig);
x10_triggers.resize(x10_triggers.size() + x0_states[i].GetNumTriggers());
for (u32 j = 0; j < x0_states[i].GetNumTriggers(); ++j) {
u32 triggerCount = in.readUint32Big();
u32 lastTriggerIdx = triggerCount - 1;
for (s32 j = 0; j < x0_states[i].GetNumTriggers(); ++j) {
const u32 triggerCount = in.readUint32Big();
const u32 lastTriggerIdx = triggerCount - 1;
for (u32 k = 0; k < triggerCount; ++k) {
std::string name = in.readString(31, false);
bool isNot = name.front() == '!';
CAiTriggerFunc func = CAi::GetTrigerFunc(isNot ? name.c_str() + 1 : name.c_str());
float arg = in.readFloatBig();
const bool isNot = name.front() == '!';
const CAiTriggerFunc func = CAi::GetTriggerFunc(isNot ? name.c_str() + 1 : name.c_str());
const float arg = in.readFloatBig();
CAiTrigger* newTrig;
if (k < lastTriggerIdx) {
newTrig = &x10_triggers.emplace_back();