This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Replace some empty array allocations with Array.Empty#1466
Merged
Conversation
Contributor
|
LGTM |
Contributor
|
👍 Are there tasks open to include FxCop in the build process and create custom rules for issues like this, usage of Console.WriteLine() in tests, and other things that keep creeping back in as new libraries are added? |
Member
Author
|
We plan to use Roslyn analyzers, but haven't done so yet as we don't yet require Roslyn for the build. |
stephentoub
added a commit
that referenced
this pull request
Apr 24, 2015
Replace some empty array allocations with Array.Empty
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
Replace some empty array allocations with Array.Empty Commit migrated from dotnet/corefx@f667d7b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Just a small cleanup...
We'd previously done a pass through the CoreFX libraries to replace most empty array allocations with "Array.Empty()". But in browsing through the code, I noticed a few more, either that we previously missed or that have crept in since.
This PR addresses those. There are still some remaining which I didn't replace, in particular ones that are returning new arrays from methods like ToArray, some of which are documented to return new arrays.
There were also some additional places I noticed that were doing their own caching of empty arrays, allocating a new array and storing it into a static. I've removed those fields and replaced the call sites with usage of Array.Empty, too.