Skip to content

Commit b622b6b

Browse files
Copilotstephentoubxtqqczze
authored
Merge PriorityQueue.Enumerator.MoveNextRare into MoveNext and use ThrowHelper for version checks (#118467)
* Merge PriorityQueue.Enumerator.MoveNextRare into MoveNext method Co-authored-by: stephentoub <[email protected]> * Use ThrowHelper.ThrowVersionCheckFailed() instead of manual exception throwing Co-authored-by: stephentoub <[email protected]> * Set _index to -1 in PriorityQueue enumerator to match List<T> pattern Co-authored-by: stephentoub <[email protected]> * Apply suggestions from code review Co-authored-by: xtqqczze <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Stephen Toub <[email protected]> Co-authored-by: xtqqczze <[email protected]>
1 parent 8fdfa4f commit b622b6b

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,25 +1012,20 @@ public bool MoveNext()
10121012
{
10131013
PriorityQueue<TElement, TPriority> localQueue = _queue;
10141014

1015-
if (_version == localQueue._version && ((uint)_index < (uint)localQueue._size))
1015+
if (_version != localQueue._version)
10161016
{
1017-
_current = localQueue._nodes[_index];
1018-
_index++;
1019-
return true;
1017+
ThrowHelper.ThrowVersionCheckFailed();
10201018
}
10211019

1022-
return MoveNextRare();
1023-
}
1024-
1025-
private bool MoveNextRare()
1026-
{
1027-
if (_version != _queue._version)
1020+
if ((uint)_index < (uint)localQueue._size)
10281021
{
1029-
throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
1022+
_current = localQueue._nodes[_index];
1023+
_index++;
1024+
return true;
10301025
}
10311026

1032-
_index = _queue._size + 1;
10331027
_current = default;
1028+
_index = -1;
10341029
return false;
10351030
}
10361031

@@ -1044,7 +1039,7 @@ void IEnumerator.Reset()
10441039
{
10451040
if (_version != _queue._version)
10461041
{
1047-
throw new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion);
1042+
ThrowHelper.ThrowVersionCheckFailed();
10481043
}
10491044

10501045
_index = 0;

0 commit comments

Comments
 (0)