Skip to content
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
12 changes: 3 additions & 9 deletions src/Mvc/Mvc.ViewFeatures/src/Buffers/PagedBufferedTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ public override Task WriteAsync(char value)
{
var flushTask = FlushAsyncCore();

// FlushAsyncCore will return CompletedTask if nothing sync buffered
// Fast-path and skip async state-machine if only a single async operation
return ReferenceEquals(flushTask, Task.CompletedTask) ?
return flushTask.IsCompletedSuccessfully ?
_inner.WriteAsync(value) :
WriteAsyncAwaited(flushTask, value);
}
Expand All @@ -126,9 +124,7 @@ public override Task WriteAsync(char[] buffer, int index, int count)
{
var flushTask = FlushAsyncCore();

// FlushAsyncCore will return CompletedTask if nothing sync buffered
// Fast-path and skip async state-machine if only a single async operation
return ReferenceEquals(flushTask, Task.CompletedTask) ?
return flushTask.IsCompletedSuccessfully ?
_inner.WriteAsync(buffer, index, count) :
WriteAsyncAwaited(flushTask, buffer, index, count);
}
Expand All @@ -143,9 +139,7 @@ public override Task WriteAsync(string value)
{
var flushTask = FlushAsyncCore();

// FlushAsyncCore will return CompletedTask if nothing sync buffered
// Fast-path and skip async state-machine if only a single async operation
return ReferenceEquals(flushTask, Task.CompletedTask) ?
return flushTask.IsCompletedSuccessfully ?
_inner.WriteAsync(value) :
WriteAsyncAwaited(flushTask, value);
}
Expand Down
13 changes: 5 additions & 8 deletions src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ private Task FireOnStartingMayAwait(Stack<KeyValuePair<Func<object, Task>, objec
while (onStarting.TryPop(out var entry))
{
var task = entry.Key.Invoke(entry.Value);
if (!ReferenceEquals(task, Task.CompletedTask))
if (!task.IsCompletedSuccessfully)
{
return FireOnStartingAwaited(task, onStarting);
}
Expand Down Expand Up @@ -817,7 +817,7 @@ private Task FireOnCompletedMayAwait(Stack<KeyValuePair<Func<object, Task>, obje
try
{
var task = entry.Key.Invoke(entry.Value);
if (!ReferenceEquals(task, Task.CompletedTask))
if (!task.IsCompletedSuccessfully)
{
return FireOnCompletedAwaited(task, onCompleted);
}
Expand Down Expand Up @@ -953,8 +953,7 @@ public void ProduceContinue()
public Task InitializeResponseAsync(int firstWriteByteCount)
{
var startingTask = FireOnStarting();
// If return is Task.CompletedTask no awaiting is required
if (!ReferenceEquals(startingTask, Task.CompletedTask))
if (!startingTask.IsCompletedSuccessfully)
{
return InitializeResponseAwaited(startingTask, firstWriteByteCount);
}
Expand Down Expand Up @@ -1397,8 +1396,7 @@ public ValueTask<FlushResult> FlushPipeAsync(CancellationToken cancellationToken
if (!HasResponseStarted)
{
var initializeTask = InitializeResponseAsync(0);
// If return is Task.CompletedTask no awaiting is required
if (!ReferenceEquals(initializeTask, Task.CompletedTask))
if (!initializeTask.IsCompletedSuccessfully)
{
return FlushAsyncAwaited(initializeTask, cancellationToken);
}
Expand Down Expand Up @@ -1509,8 +1507,7 @@ private ValueTask<FlushResult> FirstWriteAsync(ReadOnlyMemory<byte> data, Cancel
Debug.Assert(!HasResponseStarted);

var startingTask = FireOnStarting();

if (!ReferenceEquals(startingTask, Task.CompletedTask))
if (!startingTask.IsCompletedSuccessfully)
{
return FirstWriteAsyncAwaited(startingTask, data, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private Task CompleteAsyncMayAwait(Stack<KeyValuePair<Func<object, Task>, object
try
{
var task = entry.Key.Invoke(entry.Value);
if (!ReferenceEquals(task, Task.CompletedTask))
if (!task.IsCompletedSuccessfully)
{
return CompleteAsyncAwaited(task, onCompleted);
}
Expand Down