Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use the generic method
  • Loading branch information
BadSingleton committed Dec 18, 2020
commit 1325f5929bd84ca5da482cceeabdead351d39157
4 changes: 2 additions & 2 deletions src/runtime/nativecall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ internal static T GetDelegate<T>(IntPtr fp) where T: Delegate
Delegate d = null;
if (!Interop.allocatedThunks.TryGetValue(fp, out d))
{
// Use Marshal.GetDelegateForFunctionPointer<> directly after upgrade the framework
d = Marshal.GetDelegateForFunctionPointer(fp, typeof(T));
// We don't cache this delegate because this is a pure delegate ot unmanaged.
d = Marshal.GetDelegateForFunctionPointer<T>(fp);
}
return (T)d;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd save a couple instructions with:

Delegate d; // no init
if (trygetvalue(out d)) {
  return (T)d;
} else {
  return Marshal.GetDelegate...(); // no cast
}

}
Expand Down