From 2e502ce82a8a8fdcea7e700505b3fd62d5ab3226 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Thu, 22 Dec 2022 20:17:06 +0200 Subject: [PATCH] Cache managed type MonoTypeEnum values --- Source/Engine/Scripting/DotNet/MonoApi.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Scripting/DotNet/MonoApi.cpp b/Source/Engine/Scripting/DotNet/MonoApi.cpp index 5a3faa9bb..d1150daca 100644 --- a/Source/Engine/Scripting/DotNet/MonoApi.cpp +++ b/Source/Engine/Scripting/DotNet/MonoApi.cpp @@ -161,6 +161,7 @@ private: Array _properties; bool _cachedInterfaces = false; Array _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(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(GetTypeMonoTypeEnumPtr, type); + CoreCLRClass* klass = GetOrCreateClass((void*)type); + return klass->GetMonoType(); } MONO_API MonoClass* mono_type_get_class(MonoType* type)