Avoid multiple enumerations of an IEnumerable<Expression> instance in Compiler.cs (#13491)

This commit is contained in:
Dongbo Wang
2020-08-21 10:28:16 -07:00
committed by GitHub
parent ff2143d07b
commit 44bb5861cb
@@ -949,9 +949,20 @@ namespace System.Management.Automation.Language
return result;
}
private IEnumerable<Expression> CompileInvocationArguments(IEnumerable<ExpressionAst> arguments)
private IEnumerable<Expression> CompileInvocationArguments(IReadOnlyList<ExpressionAst> arguments)
{
return arguments == null ? Array.Empty<Expression>() : arguments.Select(CompileExpressionOperand);
if (arguments is null || arguments.Count == 0)
{
return Array.Empty<Expression>();
}
var result = new Expression[arguments.Count];
for (int i = 0; i < result.Length; i++)
{
result[i] = CompileExpressionOperand(arguments[i]);
}
return result;
}
internal Expression ReduceAssignment(ISupportsAssignment left, TokenKind tokenKind, Expression right)
@@ -6669,9 +6680,20 @@ namespace System.Management.Automation.Language
return _argExprTemps;
}
return InvokeMemberExpressionAst.Arguments == null
? Array.Empty<Expression>()
: InvokeMemberExpressionAst.Arguments.Select(compiler.Compile).ToArray();
ReadOnlyCollection<ExpressionAst> arguments = InvokeMemberExpressionAst.Arguments;
if (arguments is null || arguments.Count == 0)
{
return Array.Empty<Expression>();
}
var result = new Expression[arguments.Count];
for (int i = 0; i < result.Length; i++)
{
result[i] = compiler.Compile(arguments[i]);
}
return result;
}
public Expression GetValue(Compiler compiler, List<Expression> exprs, List<ParameterExpression> temps)