Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Remove unnecessary checks in ConsumeNumber (#33294) #34500

Merged
merged 2 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -647,21 +647,13 @@ private bool ConsumeNumberMultiSegment()

if (_consumed >= (uint)_buffer.Length)
{
if (!_isNotPrimitive)
{
return true;
}
if (IsLastSpan || !GetNextSpan())
{
ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, _buffer[_consumed - 1]);
}
}
Debug.Assert(IsLastSpan);

// TODO: https://github.com/dotnet/corefx/issues/33294
if (JsonConstants.Delimiters.IndexOf(_buffer[_consumed]) < 0)
{
ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, _buffer[_consumed]);
ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, _buffer[_consumed - 1]);
}

Debug.Assert(JsonConstants.Delimiters.IndexOf(_buffer[_consumed]) >= 0);

return true;
}

Expand Down Expand Up @@ -1306,7 +1298,7 @@ private ConsumeNumberResult ConsumeZeroMultiSegment(ref ReadOnlySpan<byte> data,
if (IsLastSpan)
{
// A payload containing a single value: "0" is valid
// If we are v with multi-value JSON,
// If we are dealing with multi-value JSON,
// ConsumeNumber will validate that we have a delimiter following the "0".
return ConsumeNumberResult.Success;
}
Expand Down
21 changes: 6 additions & 15 deletions src/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -685,22 +685,13 @@ private bool ConsumeNumber()

if (_consumed >= (uint)_buffer.Length)
{
if (!_isNotPrimitive)
{
return true;
}
if (IsLastSpan)
{
ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, _buffer[_consumed - 1]);
}
return false;
}
Debug.Assert(IsLastSpan);

// TODO: https://github.com/dotnet/corefx/issues/33294
if (JsonConstants.Delimiters.IndexOf(_buffer[_consumed]) < 0)
{
ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, _buffer[_consumed]);
ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, _buffer[_consumed - 1]);
}

Debug.Assert(JsonConstants.Delimiters.IndexOf(_buffer[_consumed]) >= 0);

return true;
}

Expand Down Expand Up @@ -1058,7 +1049,7 @@ private ConsumeNumberResult ConsumeZero(ref ReadOnlySpan<byte> data, ref int i)
if (IsLastSpan)
{
// A payload containing a single value: "0" is valid
// If we are v with multi-value JSON,
// If we are dealing with multi-value JSON,
// ConsumeNumber will validate that we have a delimiter following the "0".
return ConsumeNumberResult.Success;
}
Expand Down