Repository navigation
Open
Labels
enhancementThe issue or pull request is an enhancementgeneratorIssues affecting the generatoriOSIssues affecting iOSmacOSIssues affecting macOSperformanceIf an issue or pull request is related to performance
Milestone
Description
Look for them using
$ git grep NSArray src/generat*.csThere's a few example that generates them. Here's one from Trampolines.g.cs
Current Code
unsafe void Invoke (nint statusFlag1, nint statusFlag2, global::CoreNFC.EncryptionId encryptionIdentifier, NSData[] nodeKeyVersionListAes, NSData[] nodeKeyVersionListDes, NSError error)
{
if (nodeKeyVersionListAes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (nodeKeyVersionListAes));
if (nodeKeyVersionListDes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (nodeKeyVersionListDes));
var error__handle__ = error.GetHandle ();
var nsa_nodeKeyVersionListAes = nodeKeyVersionListAes is null ? null : NSArray.FromNSObjects (nodeKeyVersionListAes);
var nsa_nodeKeyVersionListDes = nodeKeyVersionListDes is null ? null : NSArray.FromNSObjects (nodeKeyVersionListDes);
invoker (BlockPointer, statusFlag1, statusFlag2, (nint) (Int64) encryptionIdentifier, nsa_nodeKeyVersionListAes is null ? IntPtr.Zero : nsa_nodeKeyVersionListAes.Handle, nsa_nodeKeyVersionListDes is null ? IntPtr.Zero : nsa_nodeKeyVersionListDes.Handle, error__handle__);
if (nsa_nodeKeyVersionListAes != null)
nsa_nodeKeyVersionListAes.Dispose ();
if (nsa_nodeKeyVersionListDes != null)
nsa_nodeKeyVersionListDes.Dispose ();
}Better Code
unsafe void Invoke (nint statusFlag1, nint statusFlag2, global::CoreNFC.EncryptionId encryptionIdentifier, NSData[] nodeKeyVersionListAes, NSData[] nodeKeyVersionListDes, NSError error)
{
if (nodeKeyVersionListAes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (nodeKeyVersionListAes));
if (nodeKeyVersionListDes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (nodeKeyVersionListDes));
var error__handle__ = error.GetHandle ();
var nodeKeyVersionListAes__handle__ = CFArray.Create (nodeKeyVersionListAes);
var nodeKeyVersionListDes__handle__ = CFArray.Create (nodeKeyVersionListDes);
invoker (BlockPointer, statusFlag1, statusFlag2, (nint) (Int64) encryptionIdentifier, nodeKeyVersionListAes__handle__, nodeKeyVersionListDes__handle__, error__handle__);
CFObject.ReleaseNative (nodeKeyVersionListAes__handle__);
CFObject.ReleaseNative (nodeKeyVersionListDes__handle__);
}Changes
- remove duplicate null checks - it's done on the argument (non null) and before creating the
NSArray - remove temporary managed
NSArraycreation - it's only created to get anHandle
Notes
The same pattern also exists in manual bindings - but there's more "bang in a buck" to fix it first inside the generator.
Reacted by Rolf Bjarne Kvinge and Filip Navara
Metadata
Metadata
Assignees
Labels
enhancementThe issue or pull request is an enhancementgeneratorIssues affecting the generatoriOSIssues affecting iOSmacOSIssues affecting macOSperformanceIf an issue or pull request is related to performance
Activity
spouliot commentedon Sep 8, 2021
Better Code v2
CFArray.Create, which would need to becomepublic, already checks fornullso...