-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
No-op ConcurrentStack.PushRange(T[]) if empty #62126
Conversation
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsResolves #62121.
|
Assert that ArgumentOutOfRangeException is thrown if specifying indexes for an empty array with PushRange(T[], int, int).
Thanks. This would address the case of I suggest the right fix is simply to change this condition: Line 413 in a4cab7d
from if (startIndex >= length || startIndex < 0) to if (startIndex > length || startIndex < 0) or even: if ((uint)startIndex > length) i.e. it should be fine to have the start index be at the end of the array, as long as the count is 0, which the subsequent check validates. |
...libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs
Outdated
Show resolved
Hide resolved
Thanks both - I did think about that, but then asking to start from index 0 (which doesn't exist) seemed to be an equally valid mistake to me at first sight on an empty array when the range is specified, so went with this initially to gauge thoughts. I'll update the PR as suggested 👍 |
Allow out-of-bounds index on empty array if count is zero.
This is how things generally work in .NET, e.g. you can insert at the end of a collection with the index == length, you can take a 0-length substring at the end of a string, etc. |
src/libraries/System.Collections.Concurrent/tests/ConcurrentStackTests.cs
Show resolved
Hide resolved
...libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs
Show resolved
Hide resolved
Add a further test case for a non-empty array but with a count parameter value of zero.
Resolves #62121.