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

Remove ~20 explicit static cctors across corefx #6016

Merged
merged 1 commit into from
Feb 11, 2016

Conversation

stephentoub
Copy link
Member

Explicit static cctors cause the C# compiler to not mark types as beforefieldinit, which in turn means that the backend compiler needs to add checks to static methods to ensure that the type has been initialized. We have a bunch of such cctors across corefx that can be easily removed; this commit does so. (See https://msdn.microsoft.com/en-us/library/ms182275.aspx for some background.)

The changes are all minor and basically boil down to converting the static cctor to one or more static methods which are then just called in the field initializer(s).

cc:
@davidsh for networking
@saurabh500 for data
@bartonjs for security
@khdang for serialization/xml
@jkotas

@saurabh500
Copy link
Contributor

@kkurni Please take a look at the data changes.


static WinHttpTraceHelper()
private static bool ReadTracingEnabled()
Copy link
Contributor

Choose a reason for hiding this comment

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

"ReadTracingEnabled" seems confusing for this method name. Why use the "Read" in the name? Why not somethng like "IsTracingEnabled"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the next method in this type is named IsTraceEnabled() 😉 I'm happy to rename this to whatever you'd prefer...

Copy link
Contributor

Choose a reason for hiding this comment

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

How about "TracingEnabledHelper"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, will rename.

@kkurni
Copy link
Contributor

kkurni commented Feb 10, 2016

LGTM for System.Data.*

@davidsh
Copy link
Contributor

davidsh commented Feb 10, 2016

cc: @CIPop

Left a comment but otherwise LGTM for networking.

@khdang
Copy link
Member

khdang commented Feb 10, 2016

LGTM for serialization.
cc: @krwq for Xml

@bartonjs
Copy link
Member

I have a general pondering of why some of these didn't move to assignment-with-collection-initializers instead of separate methods. But LGTM anyways.

@stephentoub
Copy link
Member Author

Thanks, all.

@stephentoub stephentoub force-pushed the remove_cctors branch 2 times, most recently from 41955b7 to 901825f Compare February 11, 2016 04:51
Explicit static cctors cause the C# compiler to not mark types as beforefieldinit, which in turn means that the backend compiler needs to add checks to static methods to ensure that the type has been initialized.  We have a bunch of such cctors across corefx that can be easily removed; this commit does so.  In a few places, it also presizes some collections to help avoid unnecessary memory pressure.
stephentoub added a commit that referenced this pull request Feb 11, 2016
Remove ~20 explicit static cctors across corefx
@stephentoub stephentoub merged commit 11efc0d into dotnet:master Feb 11, 2016
@stephentoub stephentoub deleted the remove_cctors branch February 11, 2016 13:48
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
dotnet-maestro-bot pushed a commit to dotnet-maestro-bot/corefx that referenced this pull request Jun 26, 2018
stephentoub pushed a commit that referenced this pull request Jun 27, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Remove ~20 explicit static cctors across corefx

Commit migrated from dotnet/corefx@11efc0d
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.

8 participants