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);
|
||||
}
|
||||
|
||||
CAiStateFunc CAiFuncMap::GetStateFunc(const char* func) {
|
||||
if (x0_stateFuncs.find(func) == x0_stateFuncs.end())
|
||||
CAiStateFunc CAiFuncMap::GetStateFunc(const char* func) const {
|
||||
const auto iter = x0_stateFuncs.find(func);
|
||||
|
||||
if (iter == x0_stateFuncs.cend()) {
|
||||
return nullptr;
|
||||
return x0_stateFuncs[func];
|
||||
}
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
CAiTriggerFunc CAiFuncMap::GetTriggerFunc(const char* func) {
|
||||
if (x10_triggerFuncs.find(func) == x10_triggerFuncs.end())
|
||||
CAiTriggerFunc CAiFuncMap::GetTriggerFunc(const char* func) const {
|
||||
const auto iter = x10_triggerFuncs.find(func);
|
||||
|
||||
if (iter == x10_triggerFuncs.cend()) {
|
||||
return nullptr;
|
||||
return x10_triggerFuncs[func];
|
||||
}
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
} // namespace urde
|
||||
|
|
|
@ -18,7 +18,7 @@ class CAiFuncMap {
|
|||
|
||||
public:
|
||||
CAiFuncMap();
|
||||
CAiStateFunc GetStateFunc(const char*);
|
||||
CAiTriggerFunc GetTriggerFunc(const char*);
|
||||
CAiStateFunc GetStateFunc(const char*) const;
|
||||
CAiTriggerFunc GetTriggerFunc(const char*) const;
|
||||
};
|
||||
} // namespace urde
|
||||
|
|
Loading…
Reference in New Issue