Skip to content

Commit

Permalink
Perf: use manual masking on state flags to avoid boxing (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored Feb 11, 2022
1 parent 5158ada commit 35d9ffe
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1197,33 +1197,38 @@ private void SetSnapshottedState(SnapshottedStateFlags flag, bool value)
}
}

private bool GetSnapshottedState(SnapshottedStateFlags flag)
{
return (_snapshottedState & flag) == flag;
}

internal bool HasOpenResult
{
get => _snapshottedState.HasFlag(SnapshottedStateFlags.OpenResult);
get => GetSnapshottedState(SnapshottedStateFlags.OpenResult);
set => SetSnapshottedState(SnapshottedStateFlags.OpenResult, value);
}

internal bool HasPendingData
{
get => _snapshottedState.HasFlag(SnapshottedStateFlags.PendingData);
get => GetSnapshottedState(SnapshottedStateFlags.PendingData);
set => SetSnapshottedState(SnapshottedStateFlags.PendingData, value);
}

internal bool HasReceivedError
{
get => _snapshottedState.HasFlag(SnapshottedStateFlags.ErrorTokenReceived);
get => GetSnapshottedState(SnapshottedStateFlags.ErrorTokenReceived);
set => SetSnapshottedState(SnapshottedStateFlags.ErrorTokenReceived, value);
}

internal bool HasReceivedAttention
{
get => _snapshottedState.HasFlag(SnapshottedStateFlags.AttentionReceived);
get => GetSnapshottedState(SnapshottedStateFlags.AttentionReceived);
set => SetSnapshottedState(SnapshottedStateFlags.AttentionReceived, value);
}

internal bool HasReceivedColumnMetadata
{
get => _snapshottedState.HasFlag(SnapshottedStateFlags.ColMetaDataReceived);
get => GetSnapshottedState(SnapshottedStateFlags.ColMetaDataReceived);
set => SetSnapshottedState(SnapshottedStateFlags.ColMetaDataReceived, value);
}

Expand Down Expand Up @@ -4291,11 +4296,11 @@ internal void ResetSnapshotState()
_stateObj._cleanupAltMetaDataSetArray = _snapshotCleanupAltMetaDataSetArray;

// Make sure to go through the appropriate increment/decrement methods if changing the OpenResult flag
if (!_stateObj.HasOpenResult && _state.HasFlag(SnapshottedStateFlags.OpenResult))
if (!_stateObj.HasOpenResult && ((_state & SnapshottedStateFlags.OpenResult) == SnapshottedStateFlags.OpenResult))
{
_stateObj.IncrementAndObtainOpenResultCount(_stateObj._executedUnderTransaction);
}
else if (_stateObj.HasOpenResult && !_state.HasFlag(SnapshottedStateFlags.OpenResult))
else if (_stateObj.HasOpenResult && ((_state & SnapshottedStateFlags.OpenResult) != SnapshottedStateFlags.OpenResult))
{
_stateObj.DecrementOpenResultCount();
}
Expand Down

0 comments on commit 35d9ffe

Please sign in to comment.