[registrar] Increase code sharing in generated `native_to_managed_trampoline_*` functions (#7221)
Several functions were 100% identical except for their signature. However the signature were over-specialized and simplifying them allows the (already) present code merge feature to achieve much better results. Final size impact will vary based on the API used (both the managed and native linker can remove some) but the more API you use the more likely the application included duplicate code. **Before** `tools/mtouch/Xamarin.iOS.registrar.ios.x86_64.m` has `native_to_managed_trampoline_[1..379]` ``` find tools/ -name Xamarin.*.a | xargs ls -l -rw-r--r-- 1 poupou staff 4143148 11 Oct 15:09 tools//mmp/Xamarin.Mac.registrar.full.a -rw-r--r-- 1 poupou staff 4139052 11 Oct 15:09 tools//mmp/Xamarin.Mac.registrar.full.x86_64.a -rw-r--r-- 1 poupou staff 4143160 11 Oct 15:09 tools//mmp/Xamarin.Mac.registrar.mobile.a -rw-r--r-- 1 poupou staff 4139064 11 Oct 15:09 tools//mmp/Xamarin.Mac.registrar.mobile.x86_64.a -rw-r--r-- 1 poupou staff 4521752 11 Oct 15:09 tools//mtouch/Xamarin.iOS.registrar.ios.i386.a -rw-r--r-- 1 poupou staff 9240416 11 Oct 15:09 tools//mtouch/Xamarin.iOS.registrar.ios.simulator.a -rw-r--r-- 1 poupou staff 4714336 11 Oct 15:09 tools//mtouch/Xamarin.iOS.registrar.ios.x86_64.a ``` **After** `tools/mtouch/Xamarin.iOS.registrar.ios.x86_64.m` has `native_to_managed_trampoline_[1..132]` ``` find tools/ -name Xamarin.*.a | xargs ls -l -rw-r--r-- 1 poupou staff 3723012 11 Oct 14:57 tools//mmp/Xamarin.Mac.registrar.full.a -rw-r--r-- 1 poupou staff 3718916 11 Oct 14:57 tools//mmp/Xamarin.Mac.registrar.full.x86_64.a -rw-r--r-- 1 poupou staff 3723016 11 Oct 14:57 tools//mmp/Xamarin.Mac.registrar.mobile.a -rw-r--r-- 1 poupou staff 3718920 11 Oct 14:57 tools//mmp/Xamarin.Mac.registrar.mobile.x86_64.a -rw-r--r-- 1 poupou staff 3995520 11 Oct 14:57 tools//mtouch/Xamarin.iOS.registrar.ios.i386.a -rw-r--r-- 1 poupou staff 8195748 11 Oct 14:57 tools//mtouch/Xamarin.iOS.registrar.ios.simulator.a -rw-r--r-- 1 poupou staff 4193956 11 Oct 14:57 tools//mtouch/Xamarin.iOS.registrar.ios.x86_64.a ```
This commit is contained in:
Родитель
911d127335
Коммит
445bf4be07
|
@ -2326,6 +2326,19 @@ namespace Registrar {
|
|||
return suggestion;
|
||||
}
|
||||
|
||||
// Some declarations can be generalized to NSObject for its subclasses
|
||||
// (and System.String too as we convert it into an NSString)
|
||||
// since the generated code, except the function signature, is identical anyway
|
||||
string ToSimpleObjCParameterType (TypeReference type, string descriptiveMethodName, List<Exception> exceptions, MemberReference inMethod)
|
||||
{
|
||||
var byref = type.IsByReference;
|
||||
var t = byref ? type.GetElementType () : type;
|
||||
if (t.Inherits ("Foundation", "NSObject") || t.Is ("System", "String"))
|
||||
return byref ? "id*" : "id";
|
||||
|
||||
return ToObjCParameterType (type, descriptiveMethodName, exceptions, inMethod);
|
||||
}
|
||||
|
||||
string ToObjCParameterType (TypeReference type, string descriptiveMethodName, List<Exception> exceptions, MemberReference inMethod)
|
||||
{
|
||||
TypeDefinition td = ResolveType (type);
|
||||
|
@ -3215,7 +3228,7 @@ namespace Registrar {
|
|||
rettype = "double";
|
||||
break;
|
||||
default:
|
||||
rettype = ToObjCParameterType (method.NativeReturnType, descriptiveMethodName, exceptions, method.Method);
|
||||
rettype = ToSimpleObjCParameterType (method.NativeReturnType, descriptiveMethodName, exceptions, method.Method);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -3962,7 +3975,7 @@ namespace Registrar {
|
|||
var objc_signature = new StringBuilder ().Append (rettype).Append (":");
|
||||
if (method.Method.HasParameters) {
|
||||
for (int i = 0; i < method.NativeParameters.Length; i++)
|
||||
objc_signature.Append (ToObjCParameterType (method.NativeParameters [i], descriptiveMethodName, exceptions, method.Method)).Append (":");
|
||||
objc_signature.Append (ToSimpleObjCParameterType (method.NativeParameters [i], descriptiveMethodName, exceptions, method.Method)).Append (":");
|
||||
}
|
||||
|
||||
Body existing;
|
||||
|
@ -3985,7 +3998,7 @@ namespace Registrar {
|
|||
methods.Append (rettype).Append (" ").Append (b.Name).Append (" (id self, SEL _cmd, MonoMethod **managed_method_ptr");
|
||||
var pcount = method.Method.HasParameters ? method.NativeParameters.Length : 0;
|
||||
for (int i = (isInstanceCategory ? 1 : 0); i < pcount; i++) {
|
||||
methods.Append (", ").Append (ToObjCParameterType (method.NativeParameters [i], descriptiveMethodName, exceptions, method.Method));
|
||||
methods.Append (", ").Append (ToSimpleObjCParameterType (method.NativeParameters [i], descriptiveMethodName, exceptions, method.Method));
|
||||
methods.Append (" ").Append ("p").Append (i.ToString ());
|
||||
}
|
||||
if (isCtor)
|
||||
|
|
Загрузка…
Ссылка в новой задаче