Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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.
- Loading branch information