Browse Source

get rid of extraneous ParserInternalState.codedInputStream field

Jan Tattermusch 5 năm trước cách đây
mục cha
commit
a1b9aa499e

+ 0 - 1
csharp/src/Google.Protobuf/CodedInputStream.cs

@@ -145,7 +145,6 @@ namespace Google.Protobuf
             this.state.sizeLimit = DefaultSizeLimit;
             this.state.recursionLimit = DefaultRecursionLimit;
             SegmentedBufferHelper.Initialize(this, out this.state.segmentedBufferHelper);
-            this.state.codedInputStream = this;
             this.leaveOpen = leaveOpen;
 
             this.state.currentLimit = int.MaxValue;

+ 1 - 1
csharp/src/Google.Protobuf/Collections/MapField.cs

@@ -695,7 +695,7 @@ namespace Google.Protobuf.Collections
                     // Read it as if we'd seen input with no data (i.e. create a "default" message).
                     if (Value == null)
                     {
-                        if (ctx.state.codedInputStream != null)
+                        if (ctx.state.CodedInputStream != null)
                         {
                             // the decoded message might not support parsing from ParseContext, so
                             // we need to allow fallback to the legacy MergeFrom(CodedInputStream) parsing.

+ 0 - 1
csharp/src/Google.Protobuf/ParseContext.cs

@@ -99,7 +99,6 @@ namespace Google.Protobuf
             SegmentedBufferHelper.Initialize(input, out ctx.state.segmentedBufferHelper, out ctx.buffer);
             ctx.state.bufferPos = 0;
             ctx.state.bufferSize = ctx.buffer.Length;
-            ctx.state.codedInputStream = null;
 
             ctx.state.DiscardUnknownFields = false;
             ctx.state.ExtensionRegistry = null;

+ 4 - 5
csharp/src/Google.Protobuf/ParserInternalState.cs

@@ -81,11 +81,6 @@ namespace Google.Protobuf
         internal int recursionDepth;  // current recursion depth
         
         internal SegmentedBufferHelper segmentedBufferHelper;
-
-        // If non-null, the top level parse method was started with given coded input stream as an argument
-        // which also means we can potentially fallback to calling MergeFrom(CodedInputStream cis) if needed.
-        internal CodedInputStream codedInputStream;
-        
         
         /// <summary>
         /// The last tag we read. 0 indicates we've read to the end of the stream
@@ -102,6 +97,10 @@ namespace Google.Protobuf
         // these fields are configuration, they should be readonly
         internal int sizeLimit;
         internal int recursionLimit;
+
+        // If non-null, the top level parse method was started with given coded input stream as an argument
+        // which also means we can potentially fallback to calling MergeFrom(CodedInputStream cis) if needed.
+        internal CodedInputStream CodedInputStream => segmentedBufferHelper.CodedInputStream;
         
         /// <summary>
         /// Internal-only property; when set to true, unknown fields will be discarded while parsing.

+ 4 - 4
csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs

@@ -182,7 +182,7 @@ namespace Google.Protobuf
                 // Regenerating the code from .proto files will remove this overhead because it will
                 // generate the InternalMergeFrom method we need.
 
-                if (ctx.state.codedInputStream == null)
+                if (ctx.state.CodedInputStream == null)
                 {
                     // This can only happen when the parsing started without providing a CodedInputStream instance
                     // (e.g. ParseContext was created directly from a ReadOnlySequence).
@@ -192,15 +192,15 @@ namespace Google.Protobuf
                     throw new InvalidProtocolBufferException($"Message {message.GetType().Name} doesn't provide the generated method that enables ParseContext-based parsing. You might need to regenerate the generated protobuf code.");
                 }
 
-                ctx.CopyStateTo(ctx.state.codedInputStream);
+                ctx.CopyStateTo(ctx.state.CodedInputStream);
                 try
                 {
                     // fallback parse using the CodedInputStream that started current parsing tree
-                    message.MergeFrom(ctx.state.codedInputStream);
+                    message.MergeFrom(ctx.state.CodedInputStream);
                 }
                 finally
                 {
-                    ctx.LoadStateFrom(ctx.state.codedInputStream);
+                    ctx.LoadStateFrom(ctx.state.CodedInputStream);
                 }
             }
         }

+ 0 - 1
csharp/src/Google.Protobuf/SegmentedBufferHelper.cs

@@ -186,7 +186,6 @@ namespace Google.Protobuf
             state.bufferSize = 0;
             while (readOnlySequenceEnumerator.MoveNext())
             {
-                
                 buffer = readOnlySequenceEnumerator.Current.Span;
                 state.bufferSize = buffer.Length;
                 if (buffer.Length != 0)