<Member Name="DangerousCreate(System.Object,T@,System.Int32)" />
<Member Name="Clear" />
<Member Name="Fill(T)" />
+ <Member Name="GetItem(System.Int32)" />
<Member Name="GetHashCode" />
<Member Name="CopyTo(System.Span<T>)" />
<Member Name="TryCopyTo(System.Span<T>)" />
<Member Name="TryCopyTo(System.Span<T>)" />
<Member Name="CopyTo(System.Span<T>)" />
</Type>
- <Type Name="System.SpanExtensions">
+ <Type Name="System.Span">
<Member Name="AsBytes<T>(System.Span<T>)" />
<Member Name="AsBytes<T>(System.ReadOnlySpan<T>)" />
<Member Name="NonPortableCast<TFrom,TTo>(System.Span<TFrom>)" />
<Member Name="NonPortableCast<TFrom,TTo>(System.ReadOnlySpan<TFrom>)" />
- </Type>
- <Type Name="System.ReadOnlySpanExtensions">
<Member Name="Slice(System.String)" />
<Member Name="Slice(System.String,System.Int32)" />
<Member Name="Slice(System.String,System.Int32,System.Int32)" />
/// </summary>
public static ReadOnlySpan<T> Empty => default(ReadOnlySpan<T>);
}
-
- public static class ReadOnlySpanExtensions
- {
- /// <summary>
- /// Creates a new readonly span over the portion of the target string.
- /// </summary>
- /// <param name="text">The target string.</param>
- /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null
- /// reference (Nothing in Visual Basic).</exception>
- public static ReadOnlySpan<char> Slice(this string text)
- {
- if (text == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text);
-
- return new ReadOnlySpan<char>(ref text.GetFirstCharRef(), text.Length);
- }
-
- /// <summary>
- /// Creates a new readonly span over the portion of the target string, beginning at 'start'.
- /// </summary>
- /// <param name="text">The target string.</param>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null
- /// reference (Nothing in Visual Basic).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> index is not in range (<0 or >Length).
- /// </exception>
- public static ReadOnlySpan<char> Slice(this string text, int start)
- {
- if (text == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text);
- if ((uint)start > (uint)text.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- return new ReadOnlySpan<char>(ref Unsafe.Add(ref text.GetFirstCharRef(), start), text.Length - start);
- }
-
- /// <summary>
- /// Creates a new readonly span over the portion of the target string, beginning at <paramref name="start"/>, of given <paramref name="length"/>.
- /// </summary>
- /// <param name="text">The target string.</param>
- /// <param name="start">The index at which to begin this slice.</param>
- /// <param name="length">The number of items in the span.</param>
- /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null
- /// reference (Nothing in Visual Basic).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
- /// Thrown when the specified <paramref name="start"/> or end index is not in range (<0 or >&eq;Length).
- /// </exception>
- public static ReadOnlySpan<char> Slice(this string text, int start, int length)
- {
- if (text == null)
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text);
- if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start))
- ThrowHelper.ThrowArgumentOutOfRangeException();
-
- return new ReadOnlySpan<char>(ref Unsafe.Add(ref text.GetFirstCharRef(), start), length);
- }
- }
}
// TODO: https://github.com/dotnet/corefx/issues/13681
// Until we get over the hurdle of C# 7 tooling, this temporary method will simulate the intended "ref T" indexer for those
// who need bypass the workaround for performance.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ //[MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [MethodImpl(MethodImplOptions.NoOptimization)] // TODO-SPAN: Workaround for https://github.com/dotnet/coreclr/issues/7894
public ref T GetItem(int index)
{
if ((uint)index >= ((uint)_length))
public static Span<T> Empty => default(Span<T>);
}
- public static class SpanExtensions
+ public static class Span
{
/// <summary>
/// Casts a Span of one primitive type <typeparamref name="T"/> to Span of bytes.
ref Unsafe.As<TFrom, TTo>(ref source.DangerousGetPinnableReference()),
checked((int)((long)source.Length * Unsafe.SizeOf<TFrom>() / Unsafe.SizeOf<TTo>())));
}
+
+ /// <summary>
+ /// Creates a new readonly span over the portion of the target string.
+ /// </summary>
+ /// <param name="text">The target string.</param>
+ /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null
+ /// reference (Nothing in Visual Basic).</exception>
+ public static ReadOnlySpan<char> Slice(this string text)
+ {
+ if (text == null)
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text);
+
+ return new ReadOnlySpan<char>(ref text.GetFirstCharRef(), text.Length);
+ }
+
+ /// <summary>
+ /// Creates a new readonly span over the portion of the target string, beginning at 'start'.
+ /// </summary>
+ /// <param name="text">The target string.</param>
+ /// <param name="start">The index at which to begin this slice.</param>
+ /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null
+ /// reference (Nothing in Visual Basic).</exception>
+ /// <exception cref="System.ArgumentOutOfRangeException">
+ /// Thrown when the specified <paramref name="start"/> index is not in range (<0 or >Length).
+ /// </exception>
+ public static ReadOnlySpan<char> Slice(this string text, int start)
+ {
+ if (text == null)
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text);
+ if ((uint)start > (uint)text.Length)
+ ThrowHelper.ThrowArgumentOutOfRangeException();
+
+ return new ReadOnlySpan<char>(ref Unsafe.Add(ref text.GetFirstCharRef(), start), text.Length - start);
+ }
+
+ /// <summary>
+ /// Creates a new readonly span over the portion of the target string, beginning at <paramref name="start"/>, of given <paramref name="length"/>.
+ /// </summary>
+ /// <param name="text">The target string.</param>
+ /// <param name="start">The index at which to begin this slice.</param>
+ /// <param name="length">The number of items in the span.</param>
+ /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="text"/> is a null
+ /// reference (Nothing in Visual Basic).</exception>
+ /// <exception cref="System.ArgumentOutOfRangeException">
+ /// Thrown when the specified <paramref name="start"/> or end index is not in range (<0 or >&eq;Length).
+ /// </exception>
+ public static ReadOnlySpan<char> Slice(this string text, int start, int length)
+ {
+ if (text == null)
+ ThrowHelper.ThrowArgumentNullException(ExceptionArgument.text);
+ if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start))
+ ThrowHelper.ThrowArgumentOutOfRangeException();
+
+ return new ReadOnlySpan<char>(ref Unsafe.Add(ref text.GetFirstCharRef(), start), length);
+ }
}
internal static class SpanHelper