Adds caching for expensive type resolution.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
36
src/ScriptResolving/AngelScript/AngelscriptUserdata.hpp
Normal file
36
src/ScriptResolving/AngelScript/AngelscriptUserdata.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef PKMNLIB_ANGELSCRIPTUSERDATA_HPP
|
||||
#define PKMNLIB_ANGELSCRIPTUSERDATA_HPP
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include "AngelScriptResolver.hpp"
|
||||
|
||||
class AngelscriptUserdata {
|
||||
AngelScriptResolver* _resolver;
|
||||
ArbUt::Dictionary<ArbUt::StringView, asITypeInfo*> _cachedTypes;
|
||||
|
||||
public:
|
||||
AngelscriptUserdata(AngelScriptResolver* r) : _resolver(r) {}
|
||||
|
||||
~AngelscriptUserdata() {
|
||||
for (auto& t : _cachedTypes) {
|
||||
t.second->Release();
|
||||
}
|
||||
}
|
||||
|
||||
asITypeInfo* GetType(const ArbUt::StringView& name) {
|
||||
auto v = _cachedTypes.TryGet(name);
|
||||
if (v.has_value()) {
|
||||
return v.value();
|
||||
}
|
||||
auto t = _resolver->GetBaseType(name);
|
||||
t->AddRef();
|
||||
_cachedTypes.Set(name, t);
|
||||
return t;
|
||||
}
|
||||
|
||||
CScriptArray* CreateArray(const ArbUt::StringView& name, size_t length) {
|
||||
auto t = GetType(name);
|
||||
return CScriptArray::Create(t, length);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_ANGELSCRIPTUSERDATA_HPP
|
||||
Reference in New Issue
Block a user