Avoid delegate allocations for ImmutableArray<T>.Any#61729
Avoid delegate allocations for ImmutableArray<T>.Any#61729sharwell merged 1 commit intodotnet:mainfrom
Conversation
|
|
||
| // If no switch sections are subsumed, just return | ||
| if (!switchSections.Any(s => s.SwitchLabels.Any(l => isSubsumed(l)))) | ||
| if (!switchSections.Any(static (s, reachableLabels) => s.SwitchLabels.Any(static (l, reachableLabels) => isSubsumed(l, reachableLabels), reachableLabels), reachableLabels)) |
There was a problem hiding this comment.
This has become hard to follow (lots of nested parens). I'd be tempted to leave the original. Or we could use local functions to factor the logic out.
There was a problem hiding this comment.
I kept thinking a language feature supporting this case would be especially helpful. For cases where static local functions were already used, I left those unchanged. However, these cases were noticeably more difficult to audit, so I did not proactively convert code from inline lambdas to local functions.
Only a very small number of cases had a significant readability impact, so I tend to prefer leaving them for now and perhaps they can be refactored in the future. It would be nice to have analyzer, IDE, and/or language support to help with the scenario.
There was a problem hiding this comment.
I'll submit a follow-up PR to simplify the inner call on this line. I'm not sure why our analyzer is failing to flag the lambda as unnecessarily complex, considering isSubsumed is already a static local function.
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 1). Only one minor concern.
This is the compiler code portion of #61719.