Skip to content

Commit

Permalink
.NET: Micro-optimizations to proxy invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 11, 2024
1 parent 7b4a186 commit 839939a
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions csharp-api/REFrameworkNET/Proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public ref class Proxy : public Reflection::DispatchProxy, public IProxy, public
auto targetReturnType = targetMethod->ReturnType;

if (targetReturnType == nullptr) {
return nullptr;
return result;
}

if (!targetReturnType->IsPrimitive && !targetReturnType->IsEnum) {
Expand Down Expand Up @@ -165,36 +165,27 @@ public ref class Proxy : public Reflection::DispatchProxy, public IProxy, public
}
}

if (targetMethod->ReturnType->IsEnum) {
auto underlyingType = targetMethod->ReturnType->GetEnumUnderlyingType();
if (targetReturnType->IsEnum) {
auto underlyingType = targetReturnType->GetEnumUnderlyingType();

if (underlyingType != nullptr) {
auto underlyingResult = Convert::ChangeType(result, underlyingType);
return Enum::ToObject(targetMethod->ReturnType, underlyingResult);
return Enum::ToObject(targetReturnType, underlyingResult);
}
}

if (targetMethod->DeclaringType == nullptr) {
return result;
}

if (!targetMethod->ReturnType->IsPrimitive && targetMethod->DeclaringType->IsInterface && result != nullptr) {
if (!targetReturnType->IsPrimitive && targetMethod->DeclaringType->IsInterface && result != nullptr) {
auto iobjectResult = dynamic_cast<REFrameworkNET::IObject^>(result);

if (iobjectResult != nullptr && targetMethod->ReturnType->IsInterface) {
/*auto t = iobjectResult->GetTypeDefinition();
auto fullName = t->FullName;
auto localType = T::typeid->Assembly->GetType(fullName);*/
auto localType = targetMethod->ReturnType;

if (localType != nullptr) {
auto proxy = DispatchProxy::Create(localType, Proxy<T, T2>::typeid->GetGenericTypeDefinition()->MakeGenericType(T::typeid, result->GetType()));
((IProxy^)proxy)->SetInstance(iobjectResult);
result = proxy;
return result;
} else {
System::Console::WriteLine("Type not found: " + targetMethod->ReturnType->FullName);
}
if (iobjectResult != nullptr && targetReturnType->IsInterface) {
auto proxy = DispatchProxy::Create(targetReturnType, Proxy<T, T2>::typeid->GetGenericTypeDefinition()->MakeGenericType(T::typeid, result->GetType()));
((IProxy^)proxy)->SetInstance(iobjectResult);
result = proxy;
return result;
}
}

Expand Down

0 comments on commit 839939a

Please sign in to comment.