-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Merge PriorityQueue.Enumerator.MoveNextRare into MoveNext and use ThrowHelper for version checks #118467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge PriorityQueue.Enumerator.MoveNextRare into MoveNext and use ThrowHelper for version checks #118467
Conversation
Co-authored-by: stephentoub <[email protected]>
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
… throwing Co-authored-by: stephentoub <[email protected]>
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: stephentoub <[email protected]>
Co-authored-by: xtqqczze <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs
Show resolved
Hide resolved
|
|
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.