Cache managed type MonoTypeEnum values

This commit is contained in:
2022-12-22 20:17:06 +02:00
parent 3c79be2910
commit 2e502ce82a

View File

@@ -161,6 +161,7 @@ private:
Array<CoreCLRProperty*> _properties;
bool _cachedInterfaces = false;
Array<CoreCLRClass*> _interfaces;
int _monoType;
public:
CoreCLRClass(void* typeHandle, StringAnsi name, StringAnsi fullname, StringAnsi namespace_, uint32 typeAttributes, CoreCLRAssembly* image)
@@ -339,6 +340,16 @@ public:
_cachedInterfaces = true;
return _interfaces;
}
int GetMonoType()
{
if (_monoType == 0)
{
static void* GetTypeMonoTypeEnumPtr = CoreCLR::GetStaticMethodPointer(TEXT("GetTypeMonoTypeEnum"));
_monoType = CoreCLR::CallStaticMethod<int, void*>(GetTypeMonoTypeEnumPtr, _typeHandle);
}
return _monoType;
}
};
struct CoreCLRMethod
@@ -1450,8 +1461,8 @@ MONO_API mono_bool mono_type_is_byref(MonoType* type)
MONO_API int mono_type_get_type(MonoType* type)
{
static void* GetTypeMonoTypeEnumPtr = CoreCLR::GetStaticMethodPointer(TEXT("GetTypeMonoTypeEnum"));
return CoreCLR::CallStaticMethod<int, void*>(GetTypeMonoTypeEnumPtr, type);
CoreCLRClass* klass = GetOrCreateClass((void*)type);
return klass->GetMonoType();
}
MONO_API MonoClass* mono_type_get_class(MonoType* type)