get rid of extraneous ParserInternalState.codedInputStream field

pull/7351/head
Jan Tattermusch 5 years ago
parent eac2a6a510
commit a1b9aa499e
  1. 1
      csharp/src/Google.Protobuf/CodedInputStream.cs
  2. 2
      csharp/src/Google.Protobuf/Collections/MapField.cs
  3. 1
      csharp/src/Google.Protobuf/ParseContext.cs
  4. 9
      csharp/src/Google.Protobuf/ParserInternalState.cs
  5. 8
      csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs
  6. 1
      csharp/src/Google.Protobuf/SegmentedBufferHelper.cs

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

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

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

@ -81,11 +81,6 @@ namespace Google.Protobuf
internal int recursionDepth; // current recursion depth internal int recursionDepth; // current recursion depth
internal SegmentedBufferHelper segmentedBufferHelper; 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> /// <summary>
/// The last tag we read. 0 indicates we've read to the end of the stream /// 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 // these fields are configuration, they should be readonly
internal int sizeLimit; internal int sizeLimit;
internal int recursionLimit; 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> /// <summary>
/// Internal-only property; when set to true, unknown fields will be discarded while parsing. /// Internal-only property; when set to true, unknown fields will be discarded while parsing.

@ -182,7 +182,7 @@ namespace Google.Protobuf
// Regenerating the code from .proto files will remove this overhead because it will // Regenerating the code from .proto files will remove this overhead because it will
// generate the InternalMergeFrom method we need. // 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 // This can only happen when the parsing started without providing a CodedInputStream instance
// (e.g. ParseContext was created directly from a ReadOnlySequence). // (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."); 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 try
{ {
// fallback parse using the CodedInputStream that started current parsing tree // fallback parse using the CodedInputStream that started current parsing tree
message.MergeFrom(ctx.state.codedInputStream); message.MergeFrom(ctx.state.CodedInputStream);
} }
finally finally
{ {
ctx.LoadStateFrom(ctx.state.codedInputStream); ctx.LoadStateFrom(ctx.state.CodedInputStream);
} }
} }
} }

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

Loading…
Cancel
Save