Simplifies UTF32Encoding/UTF8Encoding/UnicodeEncoding ctors initialization flow ...
authorMarek Safar <marek.safar@gmail.com>
Fri, 21 Sep 2018 15:07:36 +0000 (17:07 +0200)
committerJan Kotas <jkotas@microsoft.com>
Fri, 21 Sep 2018 15:07:36 +0000 (08:07 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/6654fd3e291128f1d2dee9e0a1ee49d1fd612dff

src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs
src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs
src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs

index 86169e6..39bc3f5 100644 (file)
@@ -42,27 +42,27 @@ namespace System.Text
         private static readonly byte[] s_bigEndianPreamble = new byte[4] { 0x00, 0x00, 0xFE, 0xFF };
         private static readonly byte[] s_littleEndianPreamble = new byte[4] { 0xFF, 0xFE, 0x00, 0x00 };
 
-        private bool _emitUTF32ByteOrderMark = false;
-        private bool _isThrowException = false;
-        private bool _bigEndian = false;
+        private readonly bool _emitUTF32ByteOrderMark = false;
+        private readonly bool _isThrowException = false;
+        private readonly bool _bigEndian = false;
 
 
-        public UTF32Encoding() : this(false, true, false)
+        public UTF32Encoding() : this(false, true)
         {
         }
 
 
         public UTF32Encoding(bool bigEndian, bool byteOrderMark) :
-            this(bigEndian, byteOrderMark, false)
+            base(bigEndian ? 12001 : 12000)
         {
+            _bigEndian = bigEndian;
+            _emitUTF32ByteOrderMark = byteOrderMark;
         }
 
 
         public UTF32Encoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidCharacters) :
-            base(bigEndian ? 12001 : 12000)
+            this(bigEndian, byteOrderMark)
         {
-            _bigEndian = bigEndian;
-            _emitUTF32ByteOrderMark = byteOrderMark;
             _isThrowException = throwOnInvalidCharacters;
 
             // Encoding constructor already did this, but it'll be wrong if we're throwing exceptions
index c9e51f6..672d235 100644 (file)
@@ -68,7 +68,7 @@ namespace System.Text
         // the standard.
         internal readonly bool _emitUTF8Identifier = false;
 
-        private bool _isThrowException = false;
+        private readonly bool _isThrowException = false;
 
 
         public UTF8Encoding() : this(false)
@@ -77,15 +77,15 @@ namespace System.Text
 
 
         public UTF8Encoding(bool encoderShouldEmitUTF8Identifier) :
-            this(encoderShouldEmitUTF8Identifier, false)
+            base(UTF8_CODEPAGE)
         {
+            _emitUTF8Identifier = encoderShouldEmitUTF8Identifier;
         }
 
 
         public UTF8Encoding(bool encoderShouldEmitUTF8Identifier, bool throwOnInvalidBytes) :
-            base(UTF8_CODEPAGE)
+            this(encoderShouldEmitUTF8Identifier)
         {
-            _emitUTF8Identifier = encoderShouldEmitUTF8Identifier;
             _isThrowException = throwOnInvalidBytes;
 
             // Encoding's constructor already did this, but it'll be wrong if we're throwing exceptions
index 6a27d2c..0e4ff65 100644 (file)
@@ -29,10 +29,10 @@ namespace System.Text
         private static readonly byte[] s_bigEndianPreamble = new byte[2] { 0xfe, 0xff };
         private static readonly byte[] s_littleEndianPreamble = new byte[2] { 0xff, 0xfe };
 
-        private bool isThrowException = false;
+        private readonly bool isThrowException = false;
 
-        private bool bigEndian = false;
-        private bool byteOrderMark = true;
+        private readonly bool bigEndian = false;
+        private readonly bool byteOrderMark = false;
 
         // Unicode version 2.0 character size in bytes
         public const int CharSize = 2;
@@ -44,17 +44,17 @@ namespace System.Text
 
 
         public UnicodeEncoding(bool bigEndian, bool byteOrderMark)
-            : this(bigEndian, byteOrderMark, false)
+            : base(bigEndian ? 1201 : 1200)  //Set the data item.
         {
+            this.bigEndian = bigEndian;
+            this.byteOrderMark = byteOrderMark;
         }
 
 
         public UnicodeEncoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes)
-            : base(bigEndian ? 1201 : 1200)  //Set the data item.
+            : this(bigEndian, byteOrderMark)
         {
             this.isThrowException = throwOnInvalidBytes;
-            this.bigEndian = bigEndian;
-            this.byteOrderMark = byteOrderMark;
 
             // Encoding constructor already did this, but it'll be wrong if we're throwing exceptions
             if (this.isThrowException)