Improve performance of DateTime.Kind property. (#38501)
authorSingleAccretion <62474226+SingleAccretion@users.noreply.github.com>
Thu, 9 Jul 2020 18:24:37 +0000 (21:24 +0300)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2020 18:24:37 +0000 (14:24 -0400)
* Improve performance of DateTime.Kind.

* Remove the unused field.

* Fixing whitespaces.

Co-authored-by: Ben Adams <thundercat@illyriad.co.uk>
* Revert the changes and add AgressiveInlining

* Put the attribute on the getter.

* Update src/libraries/System.Private.CoreLib/src/System/DateTime.cs

Co-authored-by: Ben Adams <thundercat@illyriad.co.uk>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Private.CoreLib/src/System/DateTime.cs

index 33b0cd2..f45333c 100644 (file)
@@ -1046,13 +1046,16 @@ namespace System
         internal bool IsAmbiguousDaylightSavingTime() =>
             InternalKind == KindLocalAmbiguousDst;
 
-        public DateTimeKind Kind =>
-            InternalKind switch
+        public DateTimeKind Kind
+        {
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
+            get => InternalKind switch
             {
                 KindUnspecified => DateTimeKind.Unspecified,
                 KindUtc => DateTimeKind.Utc,
                 _ => DateTimeKind.Local,
             };
+        }
 
         // Returns the millisecond part of this DateTime. The returned value
         // is an integer between 0 and 999.