Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a couple of unnecessary casts from Stream #55147

Merged
merged 1 commit into from Jul 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs
Expand Up @@ -201,7 +201,7 @@ public virtual ValueTask DisposeAsync()
public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) =>
BeginReadInternal(buffer, offset, count, callback, state, serializeAsynchronously: false, apm: true);

internal IAsyncResult BeginReadInternal(
internal Task<int> BeginReadInternal(
byte[] buffer, int offset, int count, AsyncCallback? callback, object? state,
bool serializeAsynchronously, bool apm)
{
Expand Down Expand Up @@ -231,7 +231,7 @@ public virtual ValueTask DisposeAsync()

// Create the task to asynchronously do a Read. This task serves both
// as the asynchronous work item and as the IAsyncResult returned to the user.
var asyncResult = new ReadWriteTask(true /*isRead*/, apm, delegate
var task = new ReadWriteTask(true /*isRead*/, apm, delegate
{
// The ReadWriteTask stores all of the parameters to pass to Read.
// As we're currently inside of it, we can get the current task
Expand Down Expand Up @@ -262,14 +262,14 @@ public virtual ValueTask DisposeAsync()
// Schedule it
if (semaphoreTask != null)
{
RunReadWriteTaskWhenReady(semaphoreTask, asyncResult);
RunReadWriteTaskWhenReady(semaphoreTask, task);
}
else
{
RunReadWriteTask(asyncResult);
RunReadWriteTask(task);
}

return asyncResult; // return it
return task; // return it
}

public virtual int EndRead(IAsyncResult asyncResult)
Expand Down Expand Up @@ -338,7 +338,7 @@ private Task<int> BeginEndReadAsync(byte[] buffer, int offset, int count)
{
// If the Stream does not override Begin/EndRead, then we can take an optimized path
// that skips an extra layer of tasks / IAsyncResults.
return (Task<int>)BeginReadInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
return BeginReadInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
}

// Otherwise, we need to wrap calls to Begin/EndWrite to ensure we use the derived type's functionality.
Expand All @@ -358,7 +358,7 @@ private struct ReadWriteParameters // struct for arguments to Read and Write cal
public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) =>
BeginWriteInternal(buffer, offset, count, callback, state, serializeAsynchronously: false, apm: true);

internal IAsyncResult BeginWriteInternal(
internal Task BeginWriteInternal(
byte[] buffer, int offset, int count, AsyncCallback? callback, object? state,
bool serializeAsynchronously, bool apm)
{
Expand Down Expand Up @@ -388,7 +388,7 @@ private struct ReadWriteParameters // struct for arguments to Read and Write cal

// Create the task to asynchronously do a Write. This task serves both
// as the asynchronous work item and as the IAsyncResult returned to the user.
var asyncResult = new ReadWriteTask(false /*isRead*/, apm, delegate
var task = new ReadWriteTask(false /*isRead*/, apm, delegate
{
// The ReadWriteTask stores all of the parameters to pass to Write.
// As we're currently inside of it, we can get the current task
Expand Down Expand Up @@ -420,14 +420,14 @@ private struct ReadWriteParameters // struct for arguments to Read and Write cal
// Schedule it
if (semaphoreTask != null)
{
RunReadWriteTaskWhenReady(semaphoreTask, asyncResult);
RunReadWriteTaskWhenReady(semaphoreTask, task);
}
else
{
RunReadWriteTask(asyncResult);
RunReadWriteTask(task);
}

return asyncResult; // return it
return task; // return it
}

private static void RunReadWriteTaskWhenReady(Task asyncWaiter, ReadWriteTask readWriteTask)
Expand Down Expand Up @@ -642,7 +642,7 @@ private Task BeginEndWriteAsync(byte[] buffer, int offset, int count)
{
// If the Stream does not override Begin/EndWrite, then we can take an optimized path
// that skips an extra layer of tasks / IAsyncResults.
return (Task)BeginWriteInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
return BeginWriteInternal(buffer, offset, count, null, null, serializeAsynchronously: true, apm: false);
}

// Otherwise, we need to wrap calls to Begin/EndWrite to ensure we use the derived type's functionality.
Expand Down