Changed internal value to readonly to all the primitive types
authorPhil Garcia <phil@thinkedge.com>
Tue, 26 Jun 2018 05:27:59 +0000 (22:27 -0700)
committerPhil Garcia <phil@thinkedge.com>
Tue, 26 Jun 2018 05:27:59 +0000 (22:27 -0700)
14 files changed:
src/System.Private.CoreLib/shared/System/Boolean.cs
src/System.Private.CoreLib/shared/System/Byte.cs
src/System.Private.CoreLib/shared/System/Char.cs
src/System.Private.CoreLib/shared/System/Double.cs
src/System.Private.CoreLib/shared/System/Int16.cs
src/System.Private.CoreLib/shared/System/Int32.cs
src/System.Private.CoreLib/shared/System/Int64.cs
src/System.Private.CoreLib/shared/System/IntPtr.cs
src/System.Private.CoreLib/shared/System/SByte.cs
src/System.Private.CoreLib/shared/System/Single.cs
src/System.Private.CoreLib/shared/System/UInt16.cs
src/System.Private.CoreLib/shared/System/UInt32.cs
src/System.Private.CoreLib/shared/System/UInt64.cs
src/System.Private.CoreLib/shared/System/UIntPtr.cs

index dbc7bd75ee5fd2d5bfee600ba9ce12bdcee0386f..7ec9227f1b55a2fca40ba3b02c19ffbb1c5f5fbc 100644 (file)
@@ -19,12 +19,12 @@ namespace System
 {
     [Serializable]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>
+    public readonly struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>
     {
         //
         // Member Variables
         //
-        private bool m_value; // Do not rename (binary serialization)
+        private readonly bool m_value; // Do not rename (binary serialization)
 
         // The true value.
         //
index 64512b0feed70e097e7a3e1b58d65d4977aabe13..5e8580642b0bfdb6ea33e61f3641c3b9b30f3632 100644 (file)
@@ -12,9 +12,9 @@ namespace System
     [Serializable]
     [StructLayout(LayoutKind.Sequential)]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct Byte : IComparable, IConvertible, IFormattable, IComparable<byte>, IEquatable<byte>, ISpanFormattable
+    public readonly struct Byte : IComparable, IConvertible, IFormattable, IComparable<byte>, IEquatable<byte>, ISpanFormattable
     {
-        private byte m_value; // Do not rename (binary serialization)
+        private readonly byte m_value; // Do not rename (binary serialization)
 
         // The maximum value that a Byte may represent: 255.
         public const byte MaxValue = (byte)0xFF;
index a3d29634020d3b5d90dc4e67a4653e4f760a7650..8c743369b1ecf64ab84ecf70ada247b09df80917 100644 (file)
@@ -21,12 +21,12 @@ namespace System
     [Serializable]
     [StructLayout(LayoutKind.Sequential)]
     [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] 
-    public struct Char : IComparable, IComparable<char>, IEquatable<char>, IConvertible
+    public readonly struct Char : IComparable, IComparable<char>, IEquatable<char>, IConvertible
     {
         //
         // Member Variables
         //
-        private char m_value; // Do not rename (binary serialization)
+        private readonly char m_value; // Do not rename (binary serialization)
 
         //
         // Public Constants
index 79021f22b886d4b7f5fe059ecd11831c0e6d9183..308dda5fadf46a00cdc5e07526b293e31ae04542 100644 (file)
@@ -26,7 +26,7 @@ namespace System
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
     public struct Double : IComparable, IConvertible, IFormattable, IComparable<double>, IEquatable<double>, ISpanFormattable
     {
-        private double m_value; // Do not rename (binary serialization)
+        private readonly double m_value; // Do not rename (binary serialization)
 
         //
         // Public Constants
@@ -226,7 +226,7 @@ namespace System
         [MethodImpl(MethodImplOptions.AggressiveInlining)] // 64-bit constants make the IL unusually large that makes the inliner to reject the method
         public override int GetHashCode()
         {
-            var bits = Unsafe.As<double, long>(ref m_value);
+            var bits = BitConverter.DoubleToInt64Bits(m_value);
 
             // Optimized check for IsNan() || IsZero()
             if (((bits - 1) & 0x7FFFFFFFFFFFFFFF) >= 0x7FF0000000000000)
index 2993337a74efb947a052f7f875bf957260431028..49732997639d25b404d2bb198f9bc04b705f7b3a 100644 (file)
@@ -12,9 +12,9 @@ namespace System
     [Serializable]
     [StructLayout(LayoutKind.Sequential)]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct Int16 : IComparable, IConvertible, IFormattable, IComparable<short>, IEquatable<short>, ISpanFormattable
+    public readonly struct Int16 : IComparable, IConvertible, IFormattable, IComparable<short>, IEquatable<short>, ISpanFormattable
     {
-        private short m_value; // Do not rename (binary serialization)
+        private readonly short m_value; // Do not rename (binary serialization)
 
         public const short MaxValue = (short)0x7FFF;
         public const short MinValue = unchecked((short)0x8000);
index 5c40812c0aabb268b5fc8d60ec7c89f71cedd143..1d0aefe73cbf202fbe542f4d3bfd0f5e28819b7c 100644 (file)
@@ -12,9 +12,9 @@ namespace System
     [Serializable]
     [StructLayout(LayoutKind.Sequential)]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct Int32 : IComparable, IConvertible, IFormattable, IComparable<int>, IEquatable<int>, ISpanFormattable
+    public readonly struct Int32 : IComparable, IConvertible, IFormattable, IComparable<int>, IEquatable<int>, ISpanFormattable
     {
-        private int m_value; // Do not rename (binary serialization)
+        private readonly int m_value; // Do not rename (binary serialization)
 
         public const int MaxValue = 0x7fffffff;
         public const int MinValue = unchecked((int)0x80000000);
index 29198781d7a8f9fc36bbfa501d597cebe69ae63d..62c9ffd4fe64dd5694dd016fc3474835a11e07c2 100644 (file)
@@ -12,9 +12,9 @@ namespace System
     [Serializable]
     [StructLayout(LayoutKind.Sequential)]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct Int64 : IComparable, IConvertible, IFormattable, IComparable<long>, IEquatable<long>, ISpanFormattable
+    public readonly struct Int64 : IComparable, IConvertible, IFormattable, IComparable<long>, IEquatable<long>, ISpanFormattable
     {
-        private long m_value; // Do not rename (binary serialization)
+        private readonly long m_value; // Do not rename (binary serialization)
 
         public const long MaxValue = 0x7fffffffffffffffL;
         public const long MinValue = unchecked((long)0x8000000000000000L);
index c5419a96e023d0cbcf4628842929f9cc36f7224f..f79334a96befd2fb7d57531fb3347e8f01dba686 100644 (file)
@@ -17,13 +17,13 @@ namespace System
 {
     [Serializable]
     [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct IntPtr : IEquatable<IntPtr>, ISerializable
+    public readonly struct IntPtr : IEquatable<IntPtr>, ISerializable
     {
         // WARNING: We allow diagnostic tools to directly inspect this member (_value). 
         // See https://github.com/dotnet/corert/blob/master/Documentation/design-docs/diagnostics/diagnostics-tools-contract.md for more details. 
         // Please do not change the type, the name, or the semantic usage of this member without understanding the implication for tools. 
         // Get in touch with the diagnostics team if you have questions.
-        private unsafe void* _value; // Do not rename (binary serialization)
+        private readonly unsafe void* _value; // Do not rename (binary serialization)
 
         [Intrinsic]
         public static readonly IntPtr Zero;
index e3c6d170a1d1aa0d53135b9f5aded0e1d088e7d3..e347e3b32301dd5373c6985161ad3a8653fcf381 100644 (file)
@@ -12,9 +12,9 @@ namespace System
     [Serializable]
     [CLSCompliant(false)]    [StructLayout(LayoutKind.Sequential)]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct SByte : IComparable, IConvertible, IFormattable, IComparable<sbyte>, IEquatable<sbyte>, ISpanFormattable
+    public readonly struct SByte : IComparable, IConvertible, IFormattable, IComparable<sbyte>, IEquatable<sbyte>, ISpanFormattable
     {
-        private sbyte m_value; // Do not rename (binary serialization)
+        private readonly sbyte m_value; // Do not rename (binary serialization)
 
         // The maximum value that a Byte may represent: 127.
         public const sbyte MaxValue = (sbyte)0x7F;
index 1a778c957c060e2c961cd7d05712a75e6d4a57c8..d62ff9ceea6f36e09cd261d11777b38b26d4e74f 100644 (file)
@@ -25,7 +25,7 @@ namespace System
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
     public struct Single : IComparable, IConvertible, IFormattable, IComparable<float>, IEquatable<float>, ISpanFormattable
     {
-        private float m_value; // Do not rename (binary serialization)
+        private readonly float m_value; // Do not rename (binary serialization)
 
         //
         // Public constants
@@ -217,7 +217,7 @@ namespace System
 
         public override int GetHashCode()
         {
-            var bits = Unsafe.As<float, int>(ref m_value);
+            var bits = BitConverter.SingleToInt32Bits(m_value);
 
             // Optimized check for IsNan() || IsZero()
             if (((bits - 1) & 0x7FFFFFFF) >= 0x7F800000)
index cd09894c6262d9d854f23780208fa8eceabe0211..f9ef1f6a624c2649c226948b1f10349e246b9f3b 100644 (file)
@@ -13,9 +13,9 @@ namespace System
     [CLSCompliant(false)]
     [StructLayout(LayoutKind.Sequential)]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct UInt16 : IComparable, IConvertible, IFormattable, IComparable<ushort>, IEquatable<ushort>, ISpanFormattable
+    public readonly struct UInt16 : IComparable, IConvertible, IFormattable, IComparable<ushort>, IEquatable<ushort>, ISpanFormattable
     {
-        private ushort m_value; // Do not rename (binary serialization)
+        private readonly ushort m_value; // Do not rename (binary serialization)
 
         public const ushort MaxValue = (ushort)0xFFFF;
         public const ushort MinValue = 0;
index d72a0a19562b511a6d9fcb64f3283e99eaf26a7c..5ed193e956269043677af1f793a827856972cd34 100644 (file)
@@ -13,9 +13,9 @@ namespace System
     [CLSCompliant(false)]
     [StructLayout(LayoutKind.Sequential)]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct UInt32 : IComparable, IConvertible, IFormattable, IComparable<uint>, IEquatable<uint>, ISpanFormattable
+    public readonly struct UInt32 : IComparable, IConvertible, IFormattable, IComparable<uint>, IEquatable<uint>, ISpanFormattable
     {
-        private uint m_value; // Do not rename (binary serialization)
+        private readonly uint m_value; // Do not rename (binary serialization)
 
         public const uint MaxValue = (uint)0xffffffff;
         public const uint MinValue = 0U;
index 3b1010a51f41b81fee9da2fb0d2cdc979315b1ee..6abd76da21f2c2e22c5c0a0e9a54daf719d7d335 100644 (file)
@@ -13,9 +13,9 @@ namespace System
     [CLSCompliant(false)]
     [StructLayout(LayoutKind.Sequential)]
     [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct UInt64 : IComparable, IConvertible, IFormattable, IComparable<ulong>, IEquatable<ulong>, ISpanFormattable
+    public readonly struct UInt64 : IComparable, IConvertible, IFormattable, IComparable<ulong>, IEquatable<ulong>, ISpanFormattable
     {
-        private ulong m_value; // Do not rename (binary serialization)
+        private readonly ulong m_value; // Do not rename (binary serialization)
 
         public const ulong MaxValue = (ulong)0xffffffffffffffffL;
         public const ulong MinValue = 0x0;
index 484eef4b61b55f7c9c274c584e3277091e622ea7..9534f4f8728090914aeaa3eb9959fc47fc53b62b 100644 (file)
@@ -18,9 +18,9 @@ namespace System
     [Serializable]
     [CLSCompliant(false)]
     [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public struct UIntPtr : IEquatable<UIntPtr>, ISerializable
+    public readonly struct UIntPtr : IEquatable<UIntPtr>, ISerializable
     {
-        private unsafe void* _value; // Do not rename (binary serialization)
+        private readonly unsafe void* _value; // Do not rename (binary serialization)
 
         [Intrinsic]
         public static readonly UIntPtr Zero;