-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Avoid some Unsafe.As
#118655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid some Unsafe.As
#118655
Conversation
No diffs expected.
Apparently, it's not no diffs |
I think it's mostly around shared generics, e.g.: using System;
using System.Runtime.CompilerServices;
using Microsoft.CodeAnalysis;
public class C
{
public static void Main(string[] args)
{
Test<string>(new string[] { "Hello", "World" });
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Test<T>(object o)
{
if (o.GetType() == typeof(T[]))
DoWork(Unsafe.As<T[]>(o));
//DoWork((T[])o);
}
[MethodImpl(MethodImplOptions.NoInlining)]
static void DoWork<T>(T[] _) { }
} |
It's fine to merge single-line changes like this, I see the current change indeed is zero diff (as expected judging by the C# code), if you can find more candidates - the better 🙂 |
Tagging subscribers to this area: @dotnet/area-system-runtime |
Looks like we have an improvement in |
@EgorBo Do we have an |
I think "reduce-unsafe" label should be enough. |
Thanks! |
No diffs expected.