Skip to content

Commit

Permalink
Remove one more lambda with closure for Nullable<T>
Browse files Browse the repository at this point in the history
Also slightly optimize creating delegates for nullable delegates
  • Loading branch information
Sergio0694 committed Jan 13, 2024
1 parent 5f5ee04 commit 87d21e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 14 additions & 3 deletions src/WinRT.Runtime/ComWrappersSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,26 @@ private static Func<IInspectable, object> CreateAbiNullableTFactory(
#endif
Type implementationType)
{
// This method is only called when 'implementationType' has been validated to be some ABI.System.Nullable_Delegate<T>.
// As such, we know that the type definitely has a method with signature 'static Nullable GetValue(IInspectable)'.
var getValueMethod = implementationType.GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic);

#if NET6_0_OR_GREATER
return getValueMethod.CreateDelegate<Func<IInspectable, ABI.System.Nullable>>();
#else
return (IInspectable obj) => getValueMethod.Invoke(null, new[] { obj });
#endif
}

private static Func<IInspectable, object> CreateArrayFactory(Type implementationType)
{
var getValueFunc = (Func<IInspectable, object>)implementationType.GetHelperType().GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic).
CreateDelegate(typeof(Func<IInspectable, object>));
return getValueFunc;
var getValueMethod = implementationType.GetHelperType().GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic);

#if NET6_0_OR_GREATER
return getValueMethod.CreateDelegate<Func<IInspectable, object>>();
#else
return (Func<IInspectable, object>)getValueMethod.CreateDelegate(typeof(Func<IInspectable, object>));
#endif
}

// This is used to hold the reference to the native value type object (IReference) until the actual value in it (boxed as an object) gets cleaned up by GC
Expand Down
9 changes: 3 additions & 6 deletions src/WinRT.Runtime/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,10 @@ internal static Type GetAuthoringMetadataType(this Type type)
{
return null;
}
else
#endif
{
// Fallback code path for back compat with previously generated projections
// running without AOT.
return GetAuthoringMetadataTypeFallback(type);
}
// Fallback code path for back compat with previously generated projections
// running without AOT.
return GetAuthoringMetadataTypeFallback(type);
});
}

Expand Down

0 comments on commit 87d21e4

Please sign in to comment.