get rid of extraneous ParserInternalState.codedInputStream field

This commit is contained in:
Jan Tattermusch 2020-04-23 16:57:47 +02:00
parent eac2a6a510
commit a1b9aa499e
6 changed files with 9 additions and 13 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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;

View File

@ -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.

View File

@ -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);
}
}
}

View File

@ -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)