Avoid allocations in DateTime.Now
authorStephen Toub <stoub@microsoft.com>
Sat, 12 Nov 2016 12:51:08 +0000 (07:51 -0500)
committerStephen Toub <stoub@microsoft.com>
Sat, 12 Nov 2016 12:52:50 +0000 (07:52 -0500)
commit2457e2b3831d73ff5178961a62f7a6fcc332eceb
treecf0b4a80f2bcc0877d5b61d5f53924d24c9e0733
parent7697dec7db3e34239ffa33d8867de12f7176e415
Avoid allocations in DateTime.Now

Every call to DateTime.Now ends up allocating a DaylightTime as it computes the offset from UtcNow.  DaylightTime is just a plain old object that stores two DateTimes and a Timespan.  Ideally we could just change it to be a struct, but it's public.  Instead, this commit adds an internal DaylightTimeStruct, which is the same as DaylightTime except as a value type, and changes some of the internal uses of DaylightTime to instead use DaylightTime.  As a result, DateTime.Now is allocation-free.
src/mscorlib/src/System/Globalization/DaylightTime.cs
src/mscorlib/src/System/TimeZoneInfo.cs