Repository navigation
Avoid multiple enumerations of an IEnumerable<Expression> instance in Compiler.cs - #13491
Conversation
Rob Holt (rjmholt)
left a comment
There was a problem hiding this comment.
Seems like a decent fix for now. It would be nice if we could remove using System.Linq; from the top of Compiler.cs and clean up all the LINQ in there
| private IEnumerable<Expression> CompileInvocationArguments(IEnumerable<ExpressionAst> arguments) | ||
| { | ||
| return arguments == null ? Array.Empty<Expression>() : arguments.Select(CompileExpressionOperand); | ||
| return arguments == null ? Array.Empty<Expression>() : arguments.Select(CompileExpressionOperand).ToArray(); |
There was a problem hiding this comment.
Looks like everywhere this method is called passes a ReadOnlyCollection<ExpressionAst>. Could type arguments as IReadOnlyList and do this:
if (arguments is null)
{
return Array.Empty<Expression>();
}
var result = new Expression[arguments.Count];
for (int i = result.Length - 1; i >= 0; i--)
{
result[i] = CompileExpressionOperand(arguments[i]);
}
return result;If you would rather not change the method parameter type then LGTM!
There was a problem hiding this comment.
Code updated.
|
Rob Holt (@rjmholt) is that an invitation? 😏 |
|
PoshChan-Bot (@PoshChan) please remind me in 20 hours |
Ilya (iSazonov)
left a comment
There was a problem hiding this comment.
Oh, it looks as a trick because these methods (InvokeMember/InvokeBaseCtorMethod/InvokeDynamicMember) still use IEnumerable type.
|
Rob Holt (@rjmholt), this is the reminder you requested 20 hours ago |
|
🎉 Handy links: |
PR Summary
Fix #13474
Avoid multiple enumerations of an
IEnumerable<Expression>instance at a few places inCompiler.cs.More than one enumeration cause the operations on individual elements of the source collection to be done repeatedly.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.