Skip to content

Commit

Permalink
Cache enum stubs and further avoid display classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jan 18, 2024
1 parent 2c9f1fd commit bba9b52
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,16 +1672,24 @@ public static T FromAbi<T>(IntPtr nativeDelegate)

internal static class Marshaler
{
internal static Action<object> EmptyFunc = (object box) => { };
internal static Func<object, object> ReturnParameterFunc = (object box) => box;
internal static readonly Action<object> EmptyFunc = Empty;
internal static readonly Func<object, object> ReturnParameterFunc = ReturnParameter;
internal static readonly Action<object, IntPtr> CopyIntEnumFunc = CopyIntEnum;
internal static readonly Action<object, IntPtr> CopyIntEnumDirectFunc = CopyIntEnumDirect;
internal static readonly Action<object, IntPtr> CopyUIntEnumFunc = CopyUIntEnum;
internal static readonly Action<object, IntPtr> CopyUIntEnumDirectFunc = CopyUIntEnumDirect;

internal static unsafe void CopyIntEnum(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)Convert.ChangeType(value, typeof(int));
private static void Empty(object arg) { }

internal static unsafe void CopyIntEnumDirect(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)value;
private static object ReturnParameter(object arg) => arg;

internal static unsafe void CopyUIntEnum(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)Convert.ChangeType(value, typeof(uint));
private static unsafe void CopyIntEnum(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)Convert.ChangeType(value, typeof(int));

internal static unsafe void CopyUIntEnumDirect(object value, IntPtr dest) => *(uint*)dest.ToPointer() = (uint)value;
private static unsafe void CopyIntEnumDirect(object value, IntPtr dest) => *(int*)dest.ToPointer() = (int)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
Expand Down

0 comments on commit bba9b52

Please sign in to comment.