{{ message }}
Merged
Conversation
Cache the delegates to native code we've created so that when we need to call that delegate, we don't ask for a delegate from a native pointer (that is a delegate to managed code.)
Contributor
Author
filmor
reviewed
Dec 17, 2020
| if (!Interop.allocatedThunks.TryGetValue(fp, out d)) | ||
| { | ||
| // Use Marshal.GetDelegateForFunctionPointer<> directly after upgrade the framework | ||
| d = Marshal.GetDelegateForFunctionPointer(fp, typeof(T)); |
Member
There was a problem hiding this comment.
Can you also apply the comment here? The generic function was introduced in .NET 4.5.1.
Member
There was a problem hiding this comment.
Actually, maybe just remove the comment. You are not writing this into allocatedThunks right now, btw.
Contributor
Author
There was a problem hiding this comment.
Yes, I don't cache these because they truly point to unmanaged code. We should only cache the function pointers to managed code.
| // We don't cache this delegate because this is a pure delegate ot unmanaged. | ||
| d = Marshal.GetDelegateForFunctionPointer<T>(fp); | ||
| } | ||
| return (T)d; |
Contributor
There was a problem hiding this comment.
You'd save a couple instructions with:
Delegate d; // no init
if (trygetvalue(out d)) {
return (T)d;
} else {
return Marshal.GetDelegate...(); // no cast
}
lostmsu
reviewed
Dec 18, 2020
Comment on lines
+45
to
+46
Member
There was a problem hiding this comment.
NIT: you don't need to assign an initial value to d. You could also do TryGetValue(fp, out var d).
lostmsu
approved these changes
Dec 18, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does this implement/fix? Explain your changes.
Cache the delegates to native code we've created so that when we need to
call that delegate, we don't ask for a delegate from a native pointer
(that is a delegate to managed code.)
Does this close any currently open issues?
This fixes issue #1323 .
Any other comments?
This is needed in order for #1287 to pass the domain reload tests on Mono.
Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG