From 47050b1067a032ae6fb7934d3ca6faeba6e3e062 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 13 Jan 2024 17:46:16 +0100 Subject: [PATCH] Cache enum stubs and further avoid display classes --- src/WinRT.Runtime/Marshalers.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index 7d2922a99..f4c7c4af0 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -1708,15 +1708,21 @@ public static T FromAbi(IntPtr nativeDelegate) internal static class Marshaler { - internal static Func ReturnParameterFunc = (object box) => box; + internal static readonly Func ReturnParameterFunc = ReturnParameter; + internal static readonly Action CopyIntEnumFunc = CopyIntEnum; + internal static readonly Action CopyIntEnumDirectFunc = CopyIntEnumDirect; + internal static readonly Action CopyUIntEnumFunc = CopyUIntEnum; + internal static readonly Action CopyUIntEnumDirectFunc = CopyUIntEnumDirect; - internal static unsafe void CopyIntEnum(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)Convert.ChangeType(value, typeof(int)); + private static object ReturnParameter(object arg) => arg; - internal static unsafe void CopyIntEnumDirect(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)value; + private static unsafe void CopyIntEnum(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)Convert.ChangeType(value, typeof(int)); - internal static unsafe void CopyUIntEnum(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)Convert.ChangeType(value, typeof(uint)); + private static unsafe void CopyIntEnumDirect(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)value; - internal static unsafe void CopyUIntEnumDirect(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)value; + private static unsafe void CopyUIntEnum(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)Convert.ChangeType(value, typeof(uint)); + + private static unsafe void CopyUIntEnumDirect(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)value; } #if EMBED