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

perf: Optimize async method allocations #328

Merged
merged 1 commit into from
Dec 5, 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 @@ -70,6 +70,8 @@ public sealed partial class SqlCommand : DbCommand, ICloneable
private static readonly DiagnosticListener _diagnosticListener = new DiagnosticListener(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName);
private bool _parentOperationStarted = false;

internal static readonly Action<object> s_cancelIgnoreFailure = CancelIgnoreFailureCallback;

// Prepare
// Against 7.0 Serve a prepare/unprepare requires an extra roundtrip to the server.
//
Expand Down Expand Up @@ -2137,7 +2139,7 @@ public override Task<int> ExecuteNonQueryAsync(CancellationToken cancellationTok
source.SetCanceled();
return source.Task;
}
registration = cancellationToken.Register(s => ((SqlCommand)s).CancelIgnoreFailure(), this);
registration = cancellationToken.Register(s_cancelIgnoreFailure, this);
}

Task<int> returnedTask = source.Task;
Expand Down Expand Up @@ -2225,7 +2227,7 @@ protected override Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior b
source.SetCanceled();
return source.Task;
}
registration = cancellationToken.Register(s => ((SqlCommand)s).CancelIgnoreFailure(), this);
registration = cancellationToken.Register(s_cancelIgnoreFailure, this);
}

Task<SqlDataReader> returnedTask = source.Task;
Expand Down Expand Up @@ -2373,7 +2375,7 @@ public Task<XmlReader> ExecuteXmlReaderAsync(CancellationToken cancellationToken
source.SetCanceled();
return source.Task;
}
registration = cancellationToken.Register(s => ((SqlCommand)s).CancelIgnoreFailure(), this);
registration = cancellationToken.Register(s_cancelIgnoreFailure, this);
}

Task<XmlReader> returnedTask = source.Task;
Expand Down Expand Up @@ -5947,6 +5949,11 @@ internal void CompletePendingReadWithFailure(int errorCode, bool resetForcePendi
}
}
#endif
internal static void CancelIgnoreFailureCallback(object state)
{
SqlCommand command = (SqlCommand)state;
command.CancelIgnoreFailure();
}

internal void CancelIgnoreFailure()
{
Expand Down
Loading