Repository navigation
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
|
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_CapacityandTrimExcessalready didn't update the version, but itsEnsureCapacitydid, andStack<T>'sTrimExcessandEnsureCapacityboth updated the version. This change just removes those unnecessary increments.Fixes #82455
Related to #81523