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

Avoid IDE030X suggestions for collection expressions that could change semantics/perf #100250

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

stephentoub
Copy link
Member

e.g. by default this will trigger IDE0300:

IEnumerable<int> source = new int[] { 0, 1, 2 };

but if that's changed to:

IEnumerable<int> source = [0, 1, 2];

the compiler tries to protect the readonly-ness of the enumerable from upcasting and emits something along the lines of:

IEnumerable<int> source = new ReadOnlyArray<int>(new int[] { 0, 1, 2 });

which is then both an extra allocation and hinders some downstream optimizations from code such as we have in LINQ that tests whether the source is a T[].

Putting this into the .editorconfig prevents the IDE from recommending switching to collection expressions in such cases.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 25, 2024
@stephentoub stephentoub requested a review from buyaa-n March 25, 2024 19:53
@stephentoub stephentoub added area-Infrastructure and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Mar 25, 2024
Copy link
Contributor

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation in the description.

@stephentoub stephentoub merged commit 25f3883 into dotnet:main Mar 25, 2024
150 of 152 checks passed
@stephentoub stephentoub deleted the collectionexpressions branch March 25, 2024 22:14
@github-actions github-actions bot locked and limited conversation to collaborators Apr 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants