diff options
author | Ben Adams <thundercat@illyriad.co.uk> | 2019-01-04 15:52:21 +0100 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2019-01-04 09:52:21 -0500 |
commit | 027a9105ae2783a7fffd6038bf07a5cf67ba287b (patch) | |
tree | afabab09c05f4f0604f91dda78c8ced0ecced9a4 | |
parent | a6269391cf04c656e9d472e1101e1ec670ecd605 (diff) | |
download | coreclr-027a9105ae2783a7fffd6038bf07a5cf67ba287b.tar.gz coreclr-027a9105ae2783a7fffd6038bf07a5cf67ba287b.tar.bz2 coreclr-027a9105ae2783a7fffd6038bf07a5cf67ba287b.zip |
Skip additional cast from common EC.Run calls (#21789)
* Skip additional cast from common EC.Run calls
* Unsafe.As
-rw-r--r-- | src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs | 7 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs | 8 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index df0e141519..cfd45f6286 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs @@ -527,7 +527,12 @@ namespace System.Runtime.CompilerServices where TStateMachine : IAsyncStateMachine { /// <summary>Delegate used to invoke on an ExecutionContext when passed an instance of this box type.</summary> - private static readonly ContextCallback s_callback = s => ((AsyncStateMachineBox<TStateMachine>)s).StateMachine.MoveNext(); + private static readonly ContextCallback s_callback = s => + { + Debug.Assert(s is AsyncStateMachineBox<TStateMachine>); + // Only used privately to pass directly to EC.Run + Unsafe.As<AsyncStateMachineBox<TStateMachine>>(s).StateMachine.MoveNext(); + }; /// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary> private Action _moveNextAction; diff --git a/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs b/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs index b9b60dd7a2..c3a4af3034 100644 --- a/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs +++ b/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @@ -17,6 +17,7 @@ using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; using Internal.Runtime.Augments; +using Internal.Runtime.CompilerServices; // Disable the "reference to volatile field not treated as volatile" error. #pragma warning disable 0420 @@ -2485,7 +2486,12 @@ namespace System.Threading.Tasks } } - private static readonly ContextCallback s_ecCallback = obj => ((Task)obj).InnerInvoke(); + private static readonly ContextCallback s_ecCallback = obj => + { + Debug.Assert(obj is Task); + // Only used privately to pass directly to EC.Run + Unsafe.As<Task>(obj).InnerInvoke(); + }; /// <summary> /// The actual code which invokes the body of the task. This can be overridden in derived types. |