提交 627168da 编写于 作者: M Manish Vasani

Address PR feedback and use singleton for null instance

上级 4dd2a449
......@@ -18,6 +18,9 @@ internal sealed partial class CSharpOperationFactory
private readonly ConcurrentDictionary<BoundNode, IOperation> _cache =
new ConcurrentDictionary<BoundNode, IOperation>(concurrencyLevel: 2, capacity: 10);
private readonly Lazy<IOperation> _lazyNullOperation =
new Lazy<IOperation>(() => null);
private readonly SemanticModel _semanticModel;
public CSharpOperationFactory(SemanticModel semanticModel)
......@@ -479,7 +482,7 @@ private IAnonymousObjectCreationOperation CreateBoundAnonymousObjectCreationExpr
private IPropertyReferenceOperation CreateBoundAnonymousPropertyDeclarationOperation(BoundAnonymousPropertyDeclaration boundAnonymousPropertyDeclaration)
{
PropertySymbol property = boundAnonymousPropertyDeclaration.Property;
Lazy<IOperation> instance = new Lazy<IOperation>(() => null);
Lazy<IOperation> instance = _lazyNullOperation;
Lazy<ImmutableArray<IArgumentOperation>> arguments = new Lazy<ImmutableArray<IArgumentOperation>>(() => ImmutableArray<IArgumentOperation>.Empty);
SyntaxNode syntax = boundAnonymousPropertyDeclaration.Syntax;
ITypeSymbol type = boundAnonymousPropertyDeclaration.Type;
......@@ -1309,7 +1312,7 @@ private IWhileLoopOperation CreateBoundWhileStatementOperation(BoundWhileStateme
{
Lazy<IOperation> condition = new Lazy<IOperation>(() => Create(boundWhileStatement.Condition));
Lazy<IOperation> body = new Lazy<IOperation>(() => Create(boundWhileStatement.Body));
Lazy<IOperation> ignoredCondition = new Lazy<IOperation>(() => null);
Lazy<IOperation> ignoredCondition = _lazyNullOperation;
ImmutableArray<ILocalSymbol> locals = boundWhileStatement.Locals.As<ILocalSymbol>();
bool conditionIsTop = true;
bool conditionIsUntil = false;
......@@ -1324,7 +1327,7 @@ private IWhileLoopOperation CreateBoundDoStatementOperation(BoundDoStatement bou
{
Lazy<IOperation> condition = new Lazy<IOperation>(() => Create(boundDoStatement.Condition));
Lazy<IOperation> body = new Lazy<IOperation>(() => Create(boundDoStatement.Body));
Lazy<IOperation> ignoredCondition = new Lazy<IOperation>(() => null);
Lazy<IOperation> ignoredCondition = _lazyNullOperation;
bool conditionIsTop = false;
bool conditionIsUntil = false;
ImmutableArray<ILocalSymbol> locals = boundDoStatement.Locals.As<ILocalSymbol>();
......@@ -1366,7 +1369,7 @@ private IForEachLoopOperation CreateBoundForEachStatementOperation(BoundForEachS
}
else
{
loopControlVariable = new Lazy<IOperation>(() => null);
loopControlVariable = _lazyNullOperation;
}
Lazy<IOperation> collection = new Lazy<IOperation>(() => Create(boundForEachStatement.Expression));
......
......@@ -13,6 +13,9 @@ Namespace Microsoft.CodeAnalysis.Operations
Private ReadOnly _cache As ConcurrentDictionary(Of BoundNode, IOperation) =
New ConcurrentDictionary(Of BoundNode, IOperation)(concurrencyLevel:=2, capacity:=10)
Private ReadOnly _lazyNothingOperation As Lazy(Of IOperation) =
New Lazy(Of IOperation)(Function() Nothing)
Private ReadOnly _semanticModel As SemanticModel
Public Sub New(semanticModel As SemanticModel)
......@@ -1215,7 +1218,7 @@ Namespace Microsoft.CodeAnalysis.Operations
Private Function CreateBoundWhileStatementOperation(boundWhileStatement As BoundWhileStatement) As IWhileLoopOperation
Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWhileStatement.Condition))
Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundWhileStatement.Body))
Dim ignoredCondition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Nothing)
Dim ignoredCondition As Lazy(Of IOperation) = _lazyNothingOperation
Dim locals As ImmutableArray(Of ILocalSymbol) = ImmutableArray(Of ILocalSymbol).Empty
Dim conditionIsTop As Boolean = True
Dim conditionIsUntil As Boolean = False
......@@ -1246,7 +1249,7 @@ Namespace Microsoft.CodeAnalysis.Operations
Private Function CreateBoundLabelStatementOperation(boundLabelStatement As BoundLabelStatement) As ILabeledOperation
Dim label As ILabelSymbol = boundLabelStatement.Label
Dim statement As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Nothing)
Dim statement As Lazy(Of IOperation) = _lazyNothingOperation
Dim syntax As SyntaxNode = boundLabelStatement.Syntax
Dim type As ITypeSymbol = Nothing
Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
......@@ -1493,7 +1496,7 @@ Namespace Microsoft.CodeAnalysis.Operations
End Function
Private Function CreateBoundAnonymousTypePropertyAccessOperation(boundAnonymousTypePropertyAccess As BoundAnonymousTypePropertyAccess) As IPropertyReferenceOperation
Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Nothing)
Dim instance As Lazy(Of IOperation) = _lazyNothingOperation
Dim [property] As IPropertySymbol = DirectCast(boundAnonymousTypePropertyAccess.ExpressionSymbol, IPropertySymbol)
Dim arguments As Lazy(Of ImmutableArray(Of IArgumentOperation)) = New Lazy(Of ImmutableArray(Of IArgumentOperation))(Function() ImmutableArray(Of IArgumentOperation).Empty)
Dim syntax As SyntaxNode = boundAnonymousTypePropertyAccess.Syntax
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册