Skip to content
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

Collection expressions: check conversion to ICollection<T> for spread optimization #74949

Merged
merged 4 commits into from
Aug 30, 2024

Conversation

cston
Copy link
Member

@cston cston commented Aug 29, 2024

Use Conversions method to check for ICollection<T> for spread optimization.

Fixes #74894

See #74630
See #74769 (comment)

@cston cston requested a review from a team as a code owner August 29, 2024 20:16
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 29, 2024
@@ -1075,17 +1077,20 @@ private BoundExpression CreateAndPopulateList(BoundCollectionExpression node, Ty

// If collection has a struct enumerator but doesn't implement ICollection<T>
// then manual `foreach` is always more efficient then using `AddRange` method
if (enumeratorInfo.GetEnumeratorInfo.Method.ReturnType.IsValueType &&
!enumeratorInfo.CollectionType.ImplementsInterface(iCollectionOfElementType, ref discardedUseSiteInfo))
if (enumeratorInfo.GetEnumeratorInfo.Method.ReturnType.IsValueType )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (enumeratorInfo.GetEnumeratorInfo.Method.ReturnType.IsValueType )
if (enumeratorInfo.GetEnumeratorInfo.Method.ReturnType.IsValueType)

@cston cston requested a review from a team August 29, 2024 20:54
@cston
Copy link
Member Author

cston commented Aug 30, 2024

@dotnet/roslyn-compiler for a second review, thanks.

@@ -1075,19 +1077,22 @@ private BoundExpression CreateAndPopulateList(BoundCollectionExpression node, Ty

// If collection has a struct enumerator but doesn't implement ICollection<T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
// If collection has a struct enumerator but doesn't implement ICollection<T>
// If collection has a struct enumerator but doesn't have a conversion to ICollection<T>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll hold off changing the comment for now because changes here will conflict with another PR in progress, and since I believe the existing comment captures the intent. We can update later if needed.

@cston cston merged commit 9907b79 into dotnet:main Aug 30, 2024
24 checks passed
@cston cston deleted the 74894 branch August 30, 2024 17:30
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Aug 30, 2024
@akhera99 akhera99 modified the milestones: Next, 17.12 P3 Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
4 participants