Skip to content

Commit fe3b0d5

Browse files
committed
.NET: Speed up generation time, fix massive local GC heap overflow
1 parent 18b301f commit fe3b0d5

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

csharp-api/REFrameworkNET/Method.cpp

+11-23
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,18 @@ ManagedObject^ Method::GetRuntimeMethod() {
2828
return nullptr;
2929
}
3030

31-
// System.Type
32-
auto runtimeType = declaringType->GetRuntimeType()/*->As<System::Type^>()*/;
33-
34-
if (runtimeType == nullptr) {
35-
return nullptr;
36-
}
37-
38-
// Iterate over all methods in the runtime type
39-
auto methods = (REFrameworkNET::ManagedObject^)runtimeType->Call("GetMethods(System.Reflection.BindingFlags)", System::Reflection::BindingFlags::Public | System::Reflection::BindingFlags::NonPublic | System::Reflection::BindingFlags::Instance | System::Reflection::BindingFlags::Static);
40-
41-
if (methods != nullptr) {
42-
auto methodDefName = this->Name;
43-
for each (REFrameworkNET::ManagedObject^ method in methods) {
44-
// Get the type handle and compare it to this (raw pointer stored in the Method object)
45-
// System.RuntimeMethodHandle automatically gets converted to a Method object
46-
auto methodHandle = (Method^)method->Call("get_MethodHandle");
47-
48-
if (methodHandle == nullptr) {
49-
continue;
50-
}
31+
auto methods = declaringType->GetRuntimeMethods();
32+
for each (REFrameworkNET::ManagedObject^ method in methods) {
33+
// Get the type handle and compare it to this (raw pointer stored in the Method object)
34+
// System.RuntimeMethodHandle automatically gets converted to a Method object
35+
auto methodHandle = (Method^)method->Call("get_MethodHandle");
36+
37+
if (methodHandle == nullptr) {
38+
continue;
39+
}
5140

52-
if (methodHandle->GetRaw() == this->GetRaw()) {
53-
return method;
54-
}
41+
if (methodHandle->GetRaw() == this->GetRaw()) {
42+
return method;
5543
}
5644
}
5745

csharp-api/REFrameworkNET/TypeDefinition.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,33 @@ namespace REFrameworkNET {
299299

300300
return m_elementType;
301301
}
302+
303+
System::Collections::Generic::List<REFrameworkNET::ManagedObject^>^ TypeDefinition::GetRuntimeMethods() {
304+
if (m_runtimeMethods == nullptr) {
305+
m_runtimeMethods = gcnew System::Collections::Generic::List<ManagedObject^>();
306+
auto runtimeType = GetRuntimeType();
307+
308+
m_lock->EnterWriteLock();
309+
310+
try {
311+
if (runtimeType != nullptr) {
312+
auto methods = (REFrameworkNET::ManagedObject^)runtimeType->Call("GetMethods(System.Reflection.BindingFlags)", System::Reflection::BindingFlags::Public | System::Reflection::BindingFlags::NonPublic | System::Reflection::BindingFlags::Instance | System::Reflection::BindingFlags::Static);
313+
314+
if (methods != nullptr) {
315+
for each (REFrameworkNET::ManagedObject^ method in methods) {
316+
if (method == nullptr) {
317+
continue;
318+
}
319+
320+
m_runtimeMethods->Add(method);
321+
}
322+
}
323+
}
324+
} finally {
325+
m_lock->ExitWriteLock();
326+
}
327+
}
328+
329+
return m_runtimeMethods;
330+
}
302331
}

csharp-api/REFrameworkNET/TypeDefinition.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ public ref class TypeDefinition : public System::Dynamic::DynamicObject,
410410
}
411411
}
412412

413+
System::Collections::Generic::List<REFrameworkNET::ManagedObject^>^ GetRuntimeMethods();
414+
413415
/*Void* GetInstance()
414416
{
415417
return m_type->get_instance();
@@ -525,5 +527,7 @@ public ref class TypeDefinition : public System::Dynamic::DynamicObject,
525527
System::Collections::Generic::List<REFrameworkNET::Method^>^ m_methods{nullptr};
526528
System::Collections::Generic::List<REFrameworkNET::Field^>^ m_fields{nullptr};
527529
System::Collections::Generic::List<REFrameworkNET::Property^>^ m_properties{nullptr};
530+
531+
System::Collections::Generic::List<REFrameworkNET::ManagedObject^>^ m_runtimeMethods{nullptr};
528532
};
529533
}

0 commit comments

Comments
 (0)