Avoid duplicated compuations with DateTime.GetDatePart
authorStephen Toub <stoub@microsoft.com>
Thu, 15 Jun 2017 15:31:12 +0000 (11:31 -0400)
committerStephen Toub <stoub@microsoft.com>
Thu, 15 Jun 2017 15:31:12 +0000 (11:31 -0400)
commit9b79839d9abdc18d436a430ec8ad1cb091df8aff
tree9ac99e915977a52c2ad4c903eb95ea317a61149a
parentf35b5a0a46ec601926a65badbd4282b62e29aeab
Avoid duplicated compuations with DateTime.GetDatePart

- Remove duplicate code in GregorianCalendar. GetDatePart is identical to the implementation in DateTime.  Just reuse it via the Year/Month/Day properties. Also avoids an unnecessary virtual call.
- Then copy GetDatePart into a version that returns year/month/day rather than just one of them.
- And use that in several places throughout corelib where all three are retrieved, avoiding redoing all of the calculations three times.

Commit migrated from https://github.com/dotnet/coreclr/commit/17c23bed6395f3e12dc0b4471b2bb566c3aa136c
src/coreclr/src/mscorlib/shared/System/DateTime.cs
src/coreclr/src/mscorlib/shared/System/Globalization/DateTimeFormat.cs
src/coreclr/src/mscorlib/shared/System/Globalization/HebrewCalendar.cs
src/coreclr/src/mscorlib/shared/System/Globalization/UmAlQuraCalendar.cs
src/coreclr/src/mscorlib/src/System/Globalization/GregorianCalendar.cs
src/coreclr/src/mscorlib/src/System/TimeZoneInfo.TransitionTime.cs