Skip to content

Commit e822dbd

Browse files
committed
Lazy-initialising a couple of collections in the context analyzer
1 parent c8b6a12 commit e822dbd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ReadableExpressions/TranslationContext.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ private class ExpressionAnalysisVisitor : ExpressionVisitor
177177
private readonly List<Expression> _assignedAssignments;
178178
private readonly Stack<BlockExpression> _blocks;
179179
private readonly Stack<object> _constructs;
180+
private ICollection<LabelTarget> _namedLabelTargets;
181+
private ICollection<GotoExpression> _gotoReturnGotos;
180182

181183
private ExpressionAnalysisVisitor()
182184
{
@@ -185,8 +187,6 @@ private ExpressionAnalysisVisitor()
185187
JoinedAssignedVariables = new List<ParameterExpression>();
186188
JoinedAssignments = new List<BinaryExpression>();
187189
_assignedAssignments = new List<Expression>();
188-
NamedLabelTargets = new List<LabelTarget>();
189-
GotoReturnGotos = new List<GotoExpression>();
190190
ChainedMethodCalls = new List<MethodCallExpression>();
191191
_blocks = new Stack<BlockExpression>();
192192
_constructs = new Stack<object>();
@@ -236,9 +236,11 @@ private static Expression GetCoreExpression(Expression expression)
236236

237237
public ICollection<BinaryExpression> JoinedAssignments { get; }
238238

239-
public ICollection<LabelTarget> NamedLabelTargets { get; }
239+
public ICollection<LabelTarget> NamedLabelTargets
240+
=> _namedLabelTargets ?? (_namedLabelTargets = new List<LabelTarget>());
240241

241-
public ICollection<GotoExpression> GotoReturnGotos { get; }
242+
public ICollection<GotoExpression> GotoReturnGotos
243+
=> _gotoReturnGotos ?? (_gotoReturnGotos = new List<GotoExpression>());
242244

243245
public List<MethodCallExpression> ChainedMethodCalls { get; }
244246

0 commit comments

Comments
 (0)