Reduce code by unifying the calls to objc_msgSend and objc_msgSendSuper
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 123
Description
We have a lot of code that does this:
```cs
if (IsDirectBinding) {
InitializeHandle (global::ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr (this.Handle, Selector.GetHandle ("initWithCoder:"), coder.Handle), "initWithCoder:");
} else {
InitializeHandle (global::ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr (this.SuperHandle, Selector.GetHandle ("initWithCoder:"), coder.Handle), "initWithCoder:");
}
```
the idea would be to be able to do something like this:
```cs
var isDirect = IsDirectBinding;
struct handles; // stack-allocated to speed things up
handles.IsDirectBinding = isDirect;
if (isDirect) {
handles.Handle = Handle;
} else {
handles.SuperHandle = SuperHandle;
}
IntPtr handle;
unsafe {
handles* ptr = &handles;
handle = global::ObjCRuntime.Messaging.IntPtr_custom_objc_msgSend_IntPtr (ptr, Selector.GetHandle ("initWithCoder:"), coder.Handle), "initWithCoder:");
}
InitializeHandle (handle);
[DllImport ("xamarin_custom_objc_msgSend")]
public unsafe static IntPtr IntPtr_custom_objc_msgSend_IntPtr (handles* handles, IntPtr sel, IntPtr p0);
```
and then in native code, we have a custom assembly routine that looks at the first argument, and depending on whether IsDirectBinding is true, fetches the Handles property and jumps to `objc_msgSend`, or fetches the SuperHandle field and jumps to `objc_msgSendSuper`.
This should make our binding code significantly smaller, while at the same time not have a very big effect on performance (although testing would be required to confirm this).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.