diff options
author | Stephen Toub <stoub@microsoft.com> | 2017-06-12 02:45:00 +0300 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2017-06-14 17:19:35 +0300 |
commit | 5f939638547b006b928706e1bc030c2bb6f43a8d (patch) | |
tree | d7ca57e89614476e46e675cae35afff8ffbd9b0b /src/System.Net.Sockets | |
parent | 4826ce0c30a35fa1748124a8c8c0b94e4d5f26e7 (diff) |
Reduce ifs / branches in StartConfiguring
Shaves a small but measurable amount off each StartConfiguring call.
Diffstat (limited to 'src/System.Net.Sockets')
-rw-r--r-- | src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs b/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs index a54ca035a0..45e1d0f8c3 100644 --- a/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs +++ b/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Diagnostics; using System.Threading; namespace System.Net.Sockets @@ -418,14 +419,23 @@ namespace System.Net.Sockets private void StartConfiguring() { int status = Interlocked.CompareExchange(ref _operating, Configuring, Free); - if (status == InProgress || status == Configuring) + if (status != Free) { - throw new InvalidOperationException(SR.net_socketopinprogress); + ThrowForNonFreeStatus(status); } - else if (status == Disposed) + } + + private void ThrowForNonFreeStatus(int status) + { + Debug.Assert(status == InProgress || status == Configuring || status == Disposed, $"Unexpected status: {status}"); + if (status == Disposed) { throw new ObjectDisposedException(GetType().FullName); } + else + { + throw new InvalidOperationException(SR.net_socketopinprogress); + } } // Prepares for a native async socket call. |