mirror of https://github.com/AxioDL/metaforce.git
CAiFuncMap: Avoid redundant map lookups in getters
We can just use the result of the find operation instead of rehashing into the map to retrieve the entry. This also allows us to make the getter const qualified.
This commit is contained in:
parent
1cfe83d8d1
commit
2f06fcba0a
|
@ -134,15 +134,23 @@ CAiFuncMap::CAiFuncMap() {
|
||||||
CAi::CreateFuncLookup(this);
|
CAi::CreateFuncLookup(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAiStateFunc CAiFuncMap::GetStateFunc(const char* func) {
|
CAiStateFunc CAiFuncMap::GetStateFunc(const char* func) const {
|
||||||
if (x0_stateFuncs.find(func) == x0_stateFuncs.end())
|
const auto iter = x0_stateFuncs.find(func);
|
||||||
|
|
||||||
|
if (iter == x0_stateFuncs.cend()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return x0_stateFuncs[func];
|
}
|
||||||
|
|
||||||
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
CAiTriggerFunc CAiFuncMap::GetTriggerFunc(const char* func) {
|
CAiTriggerFunc CAiFuncMap::GetTriggerFunc(const char* func) const {
|
||||||
if (x10_triggerFuncs.find(func) == x10_triggerFuncs.end())
|
const auto iter = x10_triggerFuncs.find(func);
|
||||||
|
|
||||||
|
if (iter == x10_triggerFuncs.cend()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return x10_triggerFuncs[func];
|
}
|
||||||
|
|
||||||
|
return iter->second;
|
||||||
}
|
}
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
|
@ -18,7 +18,7 @@ class CAiFuncMap {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CAiFuncMap();
|
CAiFuncMap();
|
||||||
CAiStateFunc GetStateFunc(const char*);
|
CAiStateFunc GetStateFunc(const char*) const;
|
||||||
CAiTriggerFunc GetTriggerFunc(const char*);
|
CAiTriggerFunc GetTriggerFunc(const char*) const;
|
||||||
};
|
};
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
Loading…
Reference in New Issue