Remove unnecessary initialization from Utf8JsonWriter ctors (#36651)
authorStephen Toub <stoub@microsoft.com>
Mon, 18 May 2020 17:47:04 +0000 (13:47 -0400)
committerGitHub <noreply@github.com>
Mon, 18 May 2020 17:47:04 +0000 (13:47 -0400)
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs

index 9ba41e0..16c00a8 100644 (file)
@@ -78,13 +78,7 @@ namespace System.Text.Json
         /// the <see cref="Utf8JsonWriter"/> which indicates whether to format the output
         /// while writing and whether to skip structural JSON validation or not.
         /// </summary>
-        public JsonWriterOptions Options
-        {
-            get
-            {
-                return _options;
-            }
-        }
+        public JsonWriterOptions Options => _options;
 
         private int Indentation => CurrentDepth * JsonConstants.SpacesPerIndent;
 
@@ -107,21 +101,7 @@ namespace System.Text.Json
         public Utf8JsonWriter(IBufferWriter<byte> bufferWriter, JsonWriterOptions options = default)
         {
             _output = bufferWriter ?? throw new ArgumentNullException(nameof(bufferWriter));
-            _stream = default;
-            _arrayBufferWriter = default;
-
-            BytesPending = default;
-            BytesCommitted = default;
-            _memory = default;
-
-            _inObject = default;
-            _tokenType = default;
-            _currentDepth = default;
             _options = options;
-
-            // Only allocate if the user writes a JSON payload beyond the depth that the _allocationFreeContainer can handle.
-            // This way we avoid allocations in the common, default cases, and allocate lazily.
-            _bitStack = default;
         }
 
         /// <summary>
@@ -142,21 +122,8 @@ namespace System.Text.Json
                 throw new ArgumentException(SR.StreamNotWritable);
 
             _stream = utf8Json;
-            _arrayBufferWriter = new ArrayBufferWriter<byte>();
-            _output = default;
-
-            BytesPending = default;
-            BytesCommitted = default;
-            _memory = default;
-
-            _inObject = default;
-            _tokenType = default;
-            _currentDepth = default;
             _options = options;
-
-            // Only allocate if the user writes a JSON payload beyond the depth that the _allocationFreeContainer can handle.
-            // This way we avoid allocations in the common, default cases, and allocate lazily.
-            _bitStack = default;
+            _arrayBufferWriter = new ArrayBufferWriter<byte>();
         }
 
         /// <summary>
@@ -249,8 +216,6 @@ namespace System.Text.Json
             _tokenType = default;
             _currentDepth = default;
 
-            // Only allocate if the user writes a JSON payload beyond the depth that the _allocationFreeContainer can handle.
-            // This way we avoid allocations in the common, default cases, and allocate lazily.
             _bitStack = default;
         }