Skip to content

Commit

Permalink
Reduce ifs / branches in StartConfiguring
Browse files Browse the repository at this point in the history
Shaves a small but measurable amount off each StartConfiguring call.
  • Loading branch information
stephentoub committed Jun 14, 2017
1 parent 4826ce0 commit 5f93963
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -418,14 +419,23 @@ public void Dispose()
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.
Expand Down

0 comments on commit 5f93963

Please sign in to comment.