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 23, 2024
1 parent 1ad78a8 commit 47050b1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,15 +1708,21 @@ public static T FromAbi<T>(IntPtr nativeDelegate)

internal static class Marshaler
{
internal static Func<object, object> ReturnParameterFunc = (object box) => box;
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 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
Expand Down

0 comments on commit 47050b1

Please sign in to comment.