diff options
author | Stephen Toub <stoub@microsoft.com> | 2018-03-21 04:27:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-21 04:27:15 -0400 |
commit | c2ba3e1370e53ca992477c4a19dddf09d9d137bb (patch) | |
tree | fcd94ab13dbcd2eb0273eaeb182387cb6abe0124 | |
parent | 4113c35a3fcfb3952da7e088158a99f003cf9cd8 (diff) | |
download | coreclr-c2ba3e1370e53ca992477c4a19dddf09d9d137bb.tar.gz coreclr-c2ba3e1370e53ca992477c4a19dddf09d9d137bb.tar.bz2 coreclr-c2ba3e1370e53ca992477c4a19dddf09d9d137bb.zip |
Avoid allocating when SuppressFlow'ing in default ExecutionContext (#17081)
* Avoid allocating when SuppressFlow'ing in default ExecutionContext
* Address PR feedback
-rw-r--r-- | src/mscorlib/shared/System/Threading/ExecutionContext.cs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/mscorlib/shared/System/Threading/ExecutionContext.cs b/src/mscorlib/shared/System/Threading/ExecutionContext.cs index 9f27c6dcb4..a840aa71fd 100644 --- a/src/mscorlib/shared/System/Threading/ExecutionContext.cs +++ b/src/mscorlib/shared/System/Threading/ExecutionContext.cs @@ -24,6 +24,7 @@ namespace System.Threading public sealed class ExecutionContext : IDisposable, ISerializable { internal static readonly ExecutionContext Default = new ExecutionContext(isDefault: true); + internal static readonly ExecutionContext DefaultFlowSuppressed = new ExecutionContext(AsyncLocalValueMap.Empty, Array.Empty<IAsyncLocal>(), isFlowSuppressed: true); private readonly IAsyncLocalValueMap m_localValues; private readonly IAsyncLocal[] m_localChangeNotifications; @@ -63,15 +64,15 @@ namespace System.Threading { Debug.Assert(isFlowSuppressed != m_isFlowSuppressed); - if (!isFlowSuppressed && - (m_localValues == null || - m_localValues.GetType() == typeof(AsyncLocalValueMap.EmptyAsyncLocalValueMap)) - ) + if (m_localValues == null || + m_localValues.GetType() == typeof(AsyncLocalValueMap.EmptyAsyncLocalValueMap)) { - return null; // implies the default context + return isFlowSuppressed ? + DefaultFlowSuppressed : + null; // implies the default context } - // Flow suppressing a Default context will have null values, set them to Empty - return new ExecutionContext(m_localValues ?? AsyncLocalValueMap.Empty, m_localChangeNotifications ?? Array.Empty<IAsyncLocal>(), isFlowSuppressed); + + return new ExecutionContext(m_localValues, m_localChangeNotifications, isFlowSuppressed); } public static AsyncFlowControl SuppressFlow() |