Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bgen] Simplify the BindAs of arrays.
If we look at the implementation of NSArray.ArrayFromHandleFunc we can see that we have the following: ```csharp // Used when we need to provide our constructor static public T [] ArrayFromHandleFunc<T> (NativeHandle handle, Func<NativeHandle, T> createObject) { if (handle == NativeHandle.Zero) return null; var c = GetCount (handle); T [] ret = new T [c]; for (uint i = 0; i < c; i++) ret [i] = createObject (GetAtIndex (handle, i)); return ret; } ``` As you can see, we do not need to check if the passed pointer to the function is IntPtr.Zero as we currently do in the generated code: ```csharp [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] [BindAs (typeof (global::CoreMedia.CMTime[]), OriginalType = typeof (NSValue[]))] public virtual global::CoreMedia.CMTime[] EnumeratedDurations { [Export ("enumeratedDurations", ArgumentSemantic.Retain)] get { global::CoreMedia.CMTime[] ret; if (IsDirectBinding) { NativeHandle retvalarrtmp; ret = ((retvalarrtmp = global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, Selector.GetHandle ("enumeratedDurations"))) == IntPtr.Zero ? null! : (NSArray.ArrayFromHandleFunc <global::CoreMedia.CMTime> (retvalarrtmp, NSValue.ToCMTime, false))); } else { NativeHandle retvalarrtmp; ret = ((retvalarrtmp = global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.SuperHandle, Selector.GetHandle ("enumeratedDurations"))) == IntPtr.Zero ? null! : (NSArray.ArrayFromHandleFunc <global::CoreMedia.CMTime> (retvalarrtmp, NSValue.ToCMTime, false))); } return ret!; } } ``` The above code can be simplified to be: ```csharp [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] [BindAs (typeof (global::CoreMedia.CMTime[]), OriginalType = typeof (NSValue[]))] public virtual global::CoreMedia.CMTime[] EnumeratedDurations { [Export ("enumeratedDurations", ArgumentSemantic.Retain)] get { global::CoreMedia.CMTime[] ret; if (IsDirectBinding) { ret = NSArray.ArrayFromHandleFunc <global::CoreMedia.CMTime> (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, Selector.GetHandle ("enumeratedDurations")), NSValue.ToCMTime, false)!; } else { ret = NSArray.ArrayFromHandleFunc <global::CoreMedia.CMTime> (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.SuperHandle, Selector.GetHandle ("enumeratedDurations")), NSValue.ToCMTime, false)!; } return ret!; } } ``` The code will have the same output when the IntPtr == IntPtr.Zero but it is simpler to understand.
- Loading branch information