Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Replace some empty array allocations with Array.Empty #1466

merged 2 commits into from Apr 24, 2015


Copy link

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


Copy link


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

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
@stephentoub stephentoub deleted the empty_arrays branch Apr 24, 2015
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet
7 participants