[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CopyTo<T>(in this ReadOnlySequence<T> source, Span<T> destination)
{
- if (source.Length > destination.Length)
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.destination);
-
if (source.IsSingleSegment)
{
- source.First.Span.CopyTo(destination);
+ ReadOnlySpan<T> span = source.First.Span;
+ if (span.Length > destination.Length)
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.destination);
+ span.CopyTo(destination);
}
else
{
private static void CopyToMultiSegment<T>(in ReadOnlySequence<T> sequence, Span<T> destination)
{
+ if (sequence.Length > destination.Length)
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.destination);
+
SequencePosition position = sequence.Start;
while (sequence.TryGet(ref position, out ReadOnlyMemory<T> memory))
{