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:
Lioncash 2019-09-08 17:55:18 -04:00
parent 1cfe83d8d1
commit 2f06fcba0a
2 changed files with 16 additions and 8 deletions

View File

@ -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

View File

@ -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