-JsonTextReader new line async performance (#1172)
This commit is contained in:
committed by
GitHub
parent
dcae8e220d
commit
1513b11d73
@@ -490,16 +490,27 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ProcessCarriageReturnAsync(bool append, CancellationToken cancellationToken)
|
private Task ProcessCarriageReturnAsync(bool append, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_charPos++;
|
_charPos++;
|
||||||
|
|
||||||
if (await EnsureCharsAsync(1, append, cancellationToken).ConfigureAwait(false) && _chars[_charPos] == StringUtils.LineFeed)
|
Task<bool> task = EnsureCharsAsync(1, append, cancellationToken);
|
||||||
|
switch (task.Status)
|
||||||
{
|
{
|
||||||
_charPos++;
|
case TaskStatus.RanToCompletion:
|
||||||
|
SetNewLine(task.Result);
|
||||||
|
return AsyncUtils.CompletedTask;
|
||||||
|
case TaskStatus.Canceled:
|
||||||
|
case TaskStatus.Faulted:
|
||||||
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
OnNewLine(_charPos);
|
return ProcessCarriageReturnAsync(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ProcessCarriageReturnAsync(Task<bool> task)
|
||||||
|
{
|
||||||
|
SetNewLine(await task.ConfigureAwait(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<char> ParseUnicodeAsync(CancellationToken cancellationToken)
|
private async Task<char> ParseUnicodeAsync(CancellationToken cancellationToken)
|
||||||
|
|||||||
@@ -120,6 +120,16 @@ namespace Newtonsoft.Json
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetNewLine(bool hasNextChar)
|
||||||
|
{
|
||||||
|
if (hasNextChar && _chars[_charPos] == StringUtils.LineFeed)
|
||||||
|
{
|
||||||
|
_charPos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
OnNewLine(_charPos);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnNewLine(int pos)
|
private void OnNewLine(int pos)
|
||||||
{
|
{
|
||||||
_lineNumber++;
|
_lineNumber++;
|
||||||
@@ -1719,12 +1729,7 @@ namespace Newtonsoft.Json
|
|||||||
{
|
{
|
||||||
_charPos++;
|
_charPos++;
|
||||||
|
|
||||||
if (EnsureChars(1, append) && _chars[_charPos] == StringUtils.LineFeed)
|
SetNewLine(EnsureChars(1, append));
|
||||||
{
|
|
||||||
_charPos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
OnNewLine(_charPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EatWhitespace()
|
private void EatWhitespace()
|
||||||
|
|||||||
Reference in New Issue
Block a user