You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of completing the MemoryExtensions feature - https://github.com/dotnet/corefx/issues/24880 - here are the proposed Span extension APIs that should get added to get parity with the available APIs on array.
Proposed API Additions
publicstaticclassMemoryExtensions{// Slice + CopyTo APIs can be used instead, hence we don't need the overloads//public static void Copy<T>(this ReadOnlySpan<T> sourceSpan, Span<T> destinationSpan, int length);//public static void Copy<T>(this ReadOnlySpan<T> sourceSpan, int sourceIndex, Span<T> destinationSpan, int destinationIndex, int length);// Span CopyTo API is already "constrained" in that if it throws an exception, the destination remains unchanged. Hence, we don't need this API//public static void ConstrainedCopy<T>(this ReadOnlySpan<T> sourceSpan, int sourceIndex, Span<T> destinationSpan, int destinationIndex, int length);publicstaticboolExists<T>(thisReadOnlySpan<T>span,Predicate<T>match);publicstatic T Find<T>(thisReadOnlySpan<T>span,Predicate<T>match);publicstaticintFindIndex<T>(thisReadOnlySpan<T>span,Predicate<T>match);// Slice the span before calling the method above, hence we don't need the overloads//public static int FindIndex<T>(this ReadOnlySpan<T> span, int startIndex, Predicate<T> match);//public static int FindIndex<T>(this ReadOnlySpan<T> span, int startIndex, int count, Predicate<T> match);publicstatic T FindLast<T>(thisReadOnlySpan<T>span,Predicate<T>match);publicstaticintFindLastIndex<T>(thisReadOnlySpan<T>span,Predicate<T>match);// Slice the span before calling the method above, hence we don't need the overloads//public static int FindLastIndex<T>(this ReadOnlySpan<T> span, int startIndex, Predicate<T> match);//public static int FindLastIndex<T>(this ReadOnlySpan<T> span, int startIndex, int count, Predicate<T> match);// Requires allocationpublicstatic T[]FindAll<T>(thisReadOnlySpan<T>span,Predicate<T>match);// Alternative to avoid allocationpublicstaticboolTryFindAll<T>(thisReadOnlySpan<T>span,Predicate<T>match,Span<T>result);publicstaticvoidReverse<T>(thisSpan<T>);// Slice the span before calling the method above, hence we don't need the overload//public static void Reverse<T>(this Span<T>, int index, int length); publicstaticboolTrueForAll<T>(thisReadOnlySpan<T>span,Predicate<T>match);}
Sample Usage and Rationale
The API usage should be almost identical to the Array API usage. Getting API parity with array makes it easier for customers to port their array-based code to Span wherever possible.
Let's only add Reverse and not the rest. Reason being that delegate invocations could potentially become a perf trap; the have obvious 1 - 5 line replacements for the caller. Reverse can be optimized and seems generally useful.
As part of completing the MemoryExtensions feature - https://github.com/dotnet/corefx/issues/24880 - here are the proposed Span extension APIs that should get added to get parity with the available APIs on array.
Proposed API Additions
Sample Usage and Rationale
The API usage should be almost identical to the Array API usage. Getting API parity with array makes it easier for customers to port their array-based code to Span wherever possible.
Example sample usage:
cc @KrzysztofCwalina, @dotnet/corefxlab-contrib, @stephentoub, @jkotas
The text was updated successfully, but these errors were encountered: