-
Notifications
You must be signed in to change notification settings - Fork 5k
API Addition: Add generic Array.Reverse<T> #14843
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
Comments
cc: @terrajobst |
I like it. |
How fast a path is the primitive fast-path? |
Actually, that should be |
Not very fast, I did a quick test in the related CoreCLR PR. And for very small arrays |
That would be a very nice addition. It's also a very simple API, and so I marked it "ready for API review" where we can discuss how to make this happen (mainly logistically). |
Assigned to @terrajobst to take it though the API review process. |
I like the APIs as well. @weshaggard, what are your thoughts? If there is no more pushback I'd mark it as |
I like the proposed API. |
dotnet/coreclr#7132 This issue can now be tagged as "api-needs-exposed" |
Add generic
Array.Reverse<T>
.Rationale
Array.Reverse
is non-generic. It includes a fast path for a known set of primitive types via a call into the runtime (seeTrySZReverse
), otherwise it falls back to slower code paths that involve boxing for value types. This is a significant performance cost for non-primitive value types, ~22x slower.Callers of
Array.Reverse
(likeList<T>.Reverse
andImmutableArray<T>.Builder.Reverse
) are affected by this performance issue. As a workaround,List<T>.Reverse
andImmutableArray<T>.Builder.Reverse
are being updated to not use the non-genericArray.Reverse
method until the genericArray.Reverse<T>
method becomes available.Other non-generic methods on
Array
have generic counterparts likeArray.Sort
andArray.Sort<T>
, so this would just be makingReverse
consistent with those.Proposed API
The text was updated successfully, but these errors were encountered: