Move BinaryReader to shared CoreLib partition (#18845)
authorJan Kotas <jkotas@microsoft.com>
Tue, 10 Jul 2018 11:13:04 +0000 (04:13 -0700)
committerGitHub <noreply@github.com>
Tue, 10 Jul 2018 11:13:04 +0000 (04:13 -0700)
src/System.Private.CoreLib/System.Private.CoreLib.csproj
src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
src/System.Private.CoreLib/shared/System/IO/BinaryReader.cs [moved from src/System.Private.CoreLib/src/System/IO/BinaryReader.cs with 98% similarity]
src/System.Private.CoreLib/src/System/Decimal.cs

index 0dda24d..c807f94 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Threading\ClrThreadPoolPreAllocatedOverlapped.cs" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="$(BclSourcesRoot)\System\IO\BinaryReader.cs" />
     <Compile Include="$(BclSourcesRoot)\System\IO\FileLoadException.CoreCLR.cs" />
     <Compile Include="$(BclSourcesRoot)\System\IO\FileNotFoundException.CoreCLR.cs" />
     <Compile Include="$(BclSourcesRoot)\System\IO\Stream.CoreCLR.cs" />
index 8b66d37..526e136 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\InvalidOperationException.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\InvalidProgramException.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\InvalidTimeZoneException.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\IO\BinaryReader.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\BinaryWriter.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\DirectoryNotFoundException.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\EncodingCache.cs" />
 **
 ============================================================*/
 
-using System;
-using System.Runtime;
+using System.Diagnostics;
 using System.Runtime.InteropServices;
 using System.Text;
-using System.Globalization;
-using System.Diagnostics;
-using System.Security;
 
 namespace System.IO
 {
@@ -220,8 +216,7 @@ namespace System.IO
 
                 Debug.Assert(charsRead < 2, "BinaryReader::ReadOneChar - assuming we only got 0 or 1 char, not 2!");
             }
-            if (charsRead == 0)
-                return -1;
+            Debug.Assert(charsRead > 0);
             return _singleChar[0];
         }
 
@@ -484,15 +479,10 @@ namespace System.IO
                 // do ~1+log(n) reads to read n characters.
                 numBytes = charsRemaining;
 
-                // special case for DecoderNLS subclasses when there is a hanging byte from the previous loop
-                DecoderNLS decoder = _decoder as DecoderNLS;
-                if (decoder != null && decoder.HasState && numBytes > 1)
-                {
-                    numBytes -= 1;
-                }
-
                 if (_2BytesPerChar)
+                {
                     numBytes <<= 1;
+                }
                 if (numBytes > MaxCharBytesSize)
                 {
                     numBytes = MaxCharBytesSize;
index d91017f..0a37664 100644 (file)
@@ -156,19 +156,16 @@ namespace System
         //
         public Decimal(int value)
         {
-            //  JIT today can't inline methods that contains "starg" opcode.
-            //  For more details, see DevDiv Bugs 81184: x86 JIT CQ: Removing the inline striction of "starg".
-            int value_copy = value;
-            if (value_copy >= 0)
+            if (value >= 0)
             {
                 flags = 0;
             }
             else
             {
                 flags = SignMask;
-                value_copy = -value_copy;
+                value = -value;
             }
-            lo = value_copy;
+            lo = value;
             mid = 0;
             hi = 0;
         }
@@ -188,20 +185,17 @@ namespace System
         //
         public Decimal(long value)
         {
-            //  JIT today can't inline methods that contains "starg" opcode.
-            //  For more details, see DevDiv Bugs 81184: x86 JIT CQ: Removing the inline striction of "starg".
-            long value_copy = value;
-            if (value_copy >= 0)
+            if (value >= 0)
             {
                 flags = 0;
             }
             else
             {
                 flags = SignMask;
-                value_copy = -value_copy;
+                value = -value;
             }
-            lo = (int)value_copy;
-            mid = (int)(value_copy >> 32);
+            lo = (int)value;
+            mid = (int)(value >> 32);
             hi = 0;
         }
 
@@ -267,15 +261,6 @@ namespace System
         //
         public Decimal(int[] bits)
         {
-            lo = 0;
-            mid = 0;
-            hi = 0;
-            flags = 0;
-            SetBits(bits);
-        }
-
-        private void SetBits(int[] bits)
-        {
             if (bits == null)
                 throw new ArgumentNullException(nameof(bits));
             if (bits.Length == 4)
@@ -313,7 +298,8 @@ namespace System
             // OnSerializing is called before serialization of an object
             try
             {
-                SetBits(GetBits(this));
+                // Run the constructor to validate the decimal
+                new decimal(lo, mid, hi, flags);
             }
             catch (ArgumentException e)
             {
@@ -327,7 +313,8 @@ namespace System
             // This callback method performs decimal validation after being deserialized.
             try
             {
-                SetBits(GetBits(this));
+                // Run the constructor to validate the decimal
+                new decimal(lo, mid, hi, flags);
             }
             catch (ArgumentException e)
             {