-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Remove unnecessary _version++ from a few places #82500
Conversation
In some collection types, resizing the backing store can affect in-flight enumerations, e.g. growing a queue will cause the implementation to relayout the elements contiguously from the beginning, which will invalidate indices stored in enumerators. But for `List<T>` and `Stack<T>`, changing the backing array doesn't impact the index stored in an enumerator, nor does it impact what the enumerator will enumerate, so these operations needn't invalidate the enumerators. `List<T>`'s `set_Capacity` and `TrimExcess` already didn't update the version, but its `EnsureCapacity` did, and `Stack<T>`'s `TrimExcess` and `EnsureCapacity` both updated the version. This change just removes those unnecessary increments.
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsIn some collection types, resizing the backing store can affect in-flight enumerations, e.g. growing a queue will cause the implementation to relayout the elements contiguously from the beginning, which will invalidate indices stored in enumerators. But for Fixes #82455
|
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.
Thanks
src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs
Show resolved
Hide resolved
e05301b
to
678e131
Compare
In some collection types, resizing the backing store can affect in-flight enumerations, e.g. growing a queue will cause the implementation to relayout the elements contiguously from the beginning, which will invalidate indices stored in enumerators. But for
List<T>
andStack<T>
, changing the backing array doesn't impact the index stored in an enumerator, nor does it impact what the enumerator will enumerate, so these operations needn't invalidate the enumerators.List<T>
'sset_Capacity
andTrimExcess
already didn't update the version, but itsEnsureCapacity
did, andStack<T>
'sTrimExcess
andEnsureCapacity
both updated the version. This change just removes those unnecessary increments.Fixes #82455
Related to #81523