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

Replace some empty array allocations with Array.Empty #1466

Merged
merged 2 commits into from
Apr 24, 2015

Conversation

stephentoub
Copy link
Member

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.

@mellinoe
Copy link
Contributor

LGTM

@hpshelton
Copy link
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?

@stephentoub
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 April 24, 2015 12:41
@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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants