Uh oh!
There was an error while loading. Please reload this page.
Merge PriorityQueue.Enumerator.MoveNextRare into MoveNext and use ThrowHelper for version checks - #118467
Conversation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
… throwing Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the PriorityQueue<TElement, TPriority>.UnorderedItemsCollection.Enumerator.MoveNext() method by inlining the MoveNextRare helper method and using ThrowHelper for better performance. The changes align the implementation with patterns used in List<T>.Enumerator after its recent improvements.
Key changes:
- Merged
MoveNextRarelogic directly intoMoveNextto eliminate method call overhead - Replaced manual exception throwing with
ThrowHelper.ThrowVersionCheckFailed()for better inlining - Changed end-of-enumeration index from
_queue._size + 1to-1for consistency with other enumerators
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
xtqqczze
commented
Aug 7, 2025
|
Uh oh!
There was an error while loading. Please reload this page.
This PR simplifies the
PriorityQueue<TElement, TPriority>.UnorderedItemsCollection.Enumerator.MoveNext()implementation by merging theMoveNextRarehelper method directly intoMoveNext, following the pattern established by the recent improvement toList<T>.Enumerator. Additionally, it replaces manual exception throwing withThrowHelpercalls to improve method inlining performance.Changes Made
MoveNextRarelogic intoMoveNext: The version validation and end-of-enumeration handling is now done directly in the mainMoveNextmethodMoveNextRarehelper method: No longer needed since its logic is integrated intoMoveNextList<T>.Enumeratorthrow new InvalidOperationException(SR.InvalidOperation_EnumFailedVersion)withSystem.Collections.ThrowHelper.ThrowVersionCheckFailed()calls in bothMoveNextandResetmethods_index = localQueue._size + 1to_index = -1to match the pattern used inList<T>.EnumeratorBefore
After
Benefits
List<T>.Enumeratorafter its recent improvement, including the-1index value for end-of-enumerationAll existing tests pass (33,438 System.Collections tests), confirming the change maintains correctness while improving the implementation.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.