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

Commit

Permalink
Remove unnecessary checks in ConsumeNumber (#33294) (#34500)
Browse files Browse the repository at this point in the history
* Remove unnecessary checks in ConsumeNumber (#33294)

* Remove unnecessary _isNotPrimitive check
  • Loading branch information
tkp1n authored and ahsonkhan committed Jan 18, 2019
1 parent 4431b3c commit d2b28cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
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 @@ -694,22 +694,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 @@ -1067,7 +1058,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

0 comments on commit d2b28cc

Please sign in to comment.