Commit f498fcf
authored
[Java.Interop] Avoid some method group conversions (#1050)
Context: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-11#improved-method-group-conversion-to-delegate
Context: #1034
Context: dotnet/roslyn#62832
C#11 introduced a "slight semantic" change with "Improved method
group conversion to delegate":
> The C# 11 compiler caches the delegate object created from a method
> group conversion and reuses that single delegate object.
The result of optimization is that for current `generator`-emitted
code such as:
static Delegate GetFooHandler ()
{
if (cb_foo == null)
cb_foo = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_V) n_Foo);
return cb_foo;
}
The `(_JniMarshal_PP_V) n_Foo` expression is a "method group
conversion", and under C#11 the generated IL is *larger*, as the
delegate instance is *cached* in case it is needed again.
However in *our* case we *know* the delegate instance won't be needed
again, not in this scope, so all this "optimization" does *for us* is
increase the size of our binding assemblies when built under C#11.
Review `src/Java.Interop` for use of `new JniNativeMethodRegistration`
and replace "cast-style" method group conversions `(D) M` to
"new-style" delegate conversions `new D(M)`. This explicitly
"opts-out" of the C#11 optimization.1 parent 16e1ecd commit f498fcf
File tree
2 files changed
+5
-5
lines changed- src/Java.Interop/Java.Interop
2 files changed
+5
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
0 commit comments