This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve RuntimeHelpers.GetSubArray (#23829)
* Improve RuntimeHelpers.GetSubArray This change does three things. First, it fixes `GetSubArray` to work when the supplied array is actually a `U[]` where `U : T`. Currently this case ends up throwing an exception inside of span, which doesn't like working with arrays covariantly. Second, it fixes argument validation so that we throw an ArgumentNullException if the input array is null rather than NullReferenceException. Third, it improves the performance of `GetSubArray` for the 95% common case where either `T` is a value type or the type of the array matches the `T` type specified. * Only use `Array.Empty<T>` when `typeof(T[]) == array.GetType()`
- Loading branch information