Skip to content

Commit 30279db

Browse files
committed
Avoid boxing an enum in MessageHandlerBase.SetState
This was allocating 8012 objects in a perf trace I took (the #1 most allocated object). It should have been 0.
1 parent 8bbb138 commit 30279db

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/StreamJsonRpc/MessageHandlerBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ public virtual async Task DisposeAsync()
253253
// If they're active, they'll take care of themselves when they finish since we signaled disposal.
254254
lock (this.syncObject)
255255
{
256-
if (!this.state.HasFlag(MessageHandlerState.Reading))
256+
if ((this.state & MessageHandlerState.Reading) != MessageHandlerState.Reading)
257257
{
258258
this.readingCompleted.Set();
259259
}
260260

261-
if (!this.state.HasFlag(MessageHandlerState.Writing))
261+
if ((this.state & MessageHandlerState.Writing) != MessageHandlerState.Writing)
262262
{
263263
this.writingCompleted.Set();
264264
}
@@ -347,7 +347,7 @@ private void SetState(MessageHandlerState startingOperation)
347347
{
348348
Verify.NotDisposed(this);
349349
MessageHandlerState state = this.state;
350-
Assumes.False(state.HasFlag(startingOperation));
350+
Assumes.False((state & startingOperation) == startingOperation);
351351
this.state |= startingOperation;
352352
}
353353
}

0 commit comments

Comments
 (0)