提交 b86b2dd0 编写于 作者: T Ty Overby 提交者: GitHub

use compare exchange for the lazy "My" Template (#17579)

* use compare exchange for the my template

* switch Object.Equals to Is
上级 30ac4ae5
......@@ -239,12 +239,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim parseOptions = If(compilationOptions.ParseOptions, VisualBasicParseOptions.Default)
Dim tree As SyntaxTree = Nothing
If s_myTemplateCache.TryGetValue(parseOptions, tree) Then
Debug.Assert(tree IsNot Nothing)
Debug.Assert(tree IsNot VisualBasicSyntaxTree.Dummy)
Debug.Assert(tree.IsMyTemplate)
_lazyMyTemplate = tree
Interlocked.CompareExchange(_lazyMyTemplate, tree, VisualBasicSyntaxTree.Dummy)
Else
' we need to make one.
Dim text As String = EmbeddedResources.VbMyTemplateText
......@@ -259,13 +260,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Throw ExceptionUtilities.Unreachable
End If
' set global cache
s_myTemplateCache(parseOptions) = tree
_lazyMyTemplate = tree
If Interlocked.CompareExchange(_lazyMyTemplate, tree, VisualBasicSyntaxTree.Dummy) Is VisualBasicSyntaxTree.Dummy Then
' set global cache
s_myTemplateCache(parseOptions) = tree
End If
End If
End If
Debug.Assert(_lazyMyTemplate Is Nothing OrElse _lazyMyTemplate.IsMyTemplate)
End If
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册