-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
@@ -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 ) |
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.
if (enumeratorInfo.GetEnumeratorInfo.Method.ReturnType.IsValueType ) | |
if (enumeratorInfo.GetEnumeratorInfo.Method.ReturnType.IsValueType) |
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs
Show resolved
Hide resolved
@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> |
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.
Nit:
// 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> |
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.
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.
Use
Conversions
method to check forICollection<T>
for spread optimization.Fixes #74894
See #74630
See #74769 (comment)