Skip to content

Commit 99cfec7

Browse files
committed
Switch binding map storage from unordered map to array
1 parent 8253cfb commit 99cfec7

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

LuaEngine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ void Eluna::CreateBindStores()
177177

178178
void Eluna::DestroyBindStores()
179179
{
180-
bindingMaps.clear();
180+
for (auto& binding : bindingMaps)
181+
binding.reset();
181182
}
182183

183184
void Eluna::RunScripts()

LuaEngine.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,13 @@ class ELUNA_GAME_API Eluna
182182
// Map from map ID -> Lua table ref
183183
std::unordered_map<uint32, int> continentDataRefs;
184184

185-
std::unordered_map<std::underlying_type_t<Hooks::RegisterTypes>, std::unique_ptr<BaseBindingMap>> bindingMaps;
185+
std::array<std::unique_ptr<BaseBindingMap>, Hooks::REGTYPE_COUNT> bindingMaps;
186186

187187
template<typename T>
188188
void CreateBinding(Hooks::RegisterTypes type)
189189
{
190-
bindingMaps[std::underlying_type_t<Hooks::RegisterTypes>(type)] = std::make_unique<BindingMap<T>>(L);
190+
auto index = static_cast<std::underlying_type_t<Hooks::RegisterTypes>>(type);
191+
bindingMaps[index] = std::make_unique<BindingMap<T>>(L);
191192
}
192193

193194
void OpenLua();
@@ -363,9 +364,14 @@ class ELUNA_GAME_API Eluna
363364
template<typename T>
364365
BindingMap<T>* GetBinding(std::underlying_type_t<Hooks::RegisterTypes> type)
365366
{
366-
auto it = bindingMaps.find(type);
367-
if (it == bindingMaps.end()) return nullptr;
368-
return dynamic_cast<BindingMap<T>*>(it->second.get());
367+
if (type >= Hooks::REGTYPE_COUNT)
368+
return nullptr;
369+
370+
auto& binding = bindingMaps[type];
371+
if (!binding)
372+
return nullptr;
373+
374+
return dynamic_cast<BindingMap<T>*>(binding.get());
369375
}
370376

371377
template<typename T>

0 commit comments

Comments
 (0)