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

Replace some empty array allocations with Array.Empty #1466

merged 2 commits into from Apr 24, 2015


Copy link

@stephentoub stephentoub commented Apr 22, 2015

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.

Copy link

@mellinoe mellinoe commented Apr 23, 2015


Copy link

@hpshelton hpshelton commented Apr 24, 2015


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?

Copy link
Member Author

@stephentoub stephentoub commented Apr 24, 2015

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
@stephentoub stephentoub merged commit f667d7b into dotnet:master Apr 24, 2015
1 check passed
1 check passed
default Merged build finished.
@stephentoub stephentoub deleted the stephentoub:empty_arrays branch Apr 24, 2015
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.