Skip to content

Commit b0ac51a

Browse files
author
maximv
committed
small optimizations for the closure const detection
1 parent e85d911 commit b0ac51a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/FastExpressionCompiler/FastExpressionCompiler.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private struct BlockInfo
394394
}
395395

396396
[Flags]
397-
internal enum ClosureStatus
397+
internal enum ClosureStatus : byte
398398
{
399399
ToBeCollected = 1,
400400
UserProvided = 1 << 1,
@@ -454,7 +454,6 @@ public ClosureInfo(ClosureStatus status, object[] constValues = null, int[] cons
454454
_blockStack = new LiveCountArray<BlockInfo>(Tools.Empty<BlockInfo>());
455455
}
456456

457-
// todo: @perf move to Status flags
458457
public bool ContainsConstantsOrNestedLambdas() => Constants.Count > 0 || NestedLambdas.Length > 0;
459458

460459
public void AddConstantOrIncrementUsageCount(object value, Type type)
@@ -1552,7 +1551,8 @@ public static bool TryEmit(Expression expr, IReadOnlyList<ParameterExpression> p
15521551
return true;
15531552
}
15541553

1555-
return TryEmitNotNullConstant(true, constExpr.Type, constExpr.Value, il, ref closure);
1554+
return TryEmitNotNullConstant(closure.ContainsConstantsOrNestedLambdas(),
1555+
constExpr.Type, constExpr.Value, il, ref closure);
15561556

15571557
case ExpressionType.Call:
15581558
return TryEmitMethodCall(expr, paramExprs, il, ref closure, parent);

0 commit comments

Comments
 (0)