-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Implement SeparatedSyntaxList.Count(Func<T, bool>) #78348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement SeparatedSyntaxList.Count(Func<T, bool>) #78348
Conversation
CSharpAttributeData.IsTargetEarlyAttribute was calling the Linq version of this list, and thus boxing the SeparatedSyntaxList enumerator, showing up as 6.5 MB (0.1%) of allocations in our OOP process during solution load. Not a huge win, but it's nice to add to the pit of success for using this type. Modifications to AttributeData just started with changing IsTargetEarlyAttribute to demonstrate the Count usage. I then looked to see what other Linq usage was in the file, and it made sense to change those too.
@@ -116,6 +116,22 @@ public static bool Any<TNode>(this SeparatedSyntaxList<TNode> list, SyntaxKind k | |||
return list.IndexOf(kind) >= 0; | |||
} | |||
|
|||
internal static int Count<TNode>(this SeparatedSyntaxList<TNode> list, Func<TNode, bool> predicate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, and I'm very amenable to moving this wherever you think appropriate. I saw the linq-like extension methods right above this one, so that is where I put this, but if you think there's a better place for this, I'll go ahead and move it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is nothing C# specific in this helper, I think it should not be added to CSharpExtensions. Please look for a better place so that VB code could also take advantage of the helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to a non-C# specific location, but kept as an extension method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 2)
CSharpAttributeData.IsTargetEarlyAttribute was calling the Linq version of this list, and thus boxing the SeparatedSyntaxList enumerator, showing up as 5.9 MB (0.1%) of allocations in our OOP process during solution load.
Not a huge win, but it's nice to add to the pit of success for using this type.
Modifications to CSharpAttributeData started with a small cleanup to IsTargetEarlyAttribute to demonstrate the Count() usage. I then looked to see what other Linq usage was in the file, and it made sense to change those too.
*** Allocations in question ***
