Skip to content

Commit 35d9ffe

Browse files
authored
Perf: use manual masking on state flags to avoid boxing (#1197)
1 parent 5158ada commit 35d9ffe

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,33 +1197,38 @@ private void SetSnapshottedState(SnapshottedStateFlags flag, bool value)
11971197
}
11981198
}
11991199

1200+
private bool GetSnapshottedState(SnapshottedStateFlags flag)
1201+
{
1202+
return (_snapshottedState & flag) == flag;
1203+
}
1204+
12001205
internal bool HasOpenResult
12011206
{
1202-
get => _snapshottedState.HasFlag(SnapshottedStateFlags.OpenResult);
1207+
get => GetSnapshottedState(SnapshottedStateFlags.OpenResult);
12031208
set => SetSnapshottedState(SnapshottedStateFlags.OpenResult, value);
12041209
}
12051210

12061211
internal bool HasPendingData
12071212
{
1208-
get => _snapshottedState.HasFlag(SnapshottedStateFlags.PendingData);
1213+
get => GetSnapshottedState(SnapshottedStateFlags.PendingData);
12091214
set => SetSnapshottedState(SnapshottedStateFlags.PendingData, value);
12101215
}
12111216

12121217
internal bool HasReceivedError
12131218
{
1214-
get => _snapshottedState.HasFlag(SnapshottedStateFlags.ErrorTokenReceived);
1219+
get => GetSnapshottedState(SnapshottedStateFlags.ErrorTokenReceived);
12151220
set => SetSnapshottedState(SnapshottedStateFlags.ErrorTokenReceived, value);
12161221
}
12171222

12181223
internal bool HasReceivedAttention
12191224
{
1220-
get => _snapshottedState.HasFlag(SnapshottedStateFlags.AttentionReceived);
1225+
get => GetSnapshottedState(SnapshottedStateFlags.AttentionReceived);
12211226
set => SetSnapshottedState(SnapshottedStateFlags.AttentionReceived, value);
12221227
}
12231228

12241229
internal bool HasReceivedColumnMetadata
12251230
{
1226-
get => _snapshottedState.HasFlag(SnapshottedStateFlags.ColMetaDataReceived);
1231+
get => GetSnapshottedState(SnapshottedStateFlags.ColMetaDataReceived);
12271232
set => SetSnapshottedState(SnapshottedStateFlags.ColMetaDataReceived, value);
12281233
}
12291234

@@ -4291,11 +4296,11 @@ internal void ResetSnapshotState()
42914296
_stateObj._cleanupAltMetaDataSetArray = _snapshotCleanupAltMetaDataSetArray;
42924297

42934298
// Make sure to go through the appropriate increment/decrement methods if changing the OpenResult flag
4294-
if (!_stateObj.HasOpenResult && _state.HasFlag(SnapshottedStateFlags.OpenResult))
4299+
if (!_stateObj.HasOpenResult && ((_state & SnapshottedStateFlags.OpenResult) == SnapshottedStateFlags.OpenResult))
42954300
{
42964301
_stateObj.IncrementAndObtainOpenResultCount(_stateObj._executedUnderTransaction);
42974302
}
4298-
else if (_stateObj.HasOpenResult && !_state.HasFlag(SnapshottedStateFlags.OpenResult))
4303+
else if (_stateObj.HasOpenResult && ((_state & SnapshottedStateFlags.OpenResult) != SnapshottedStateFlags.OpenResult))
42994304
{
43004305
_stateObj.DecrementOpenResultCount();
43014306
}

0 commit comments

Comments
 (0)