Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Aug 30, 2023
1 parent fb3f25a commit f8d8b03
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace System;
Expand Down Expand Up @@ -55,13 +56,18 @@ private void InnerCopyToChecked(
return;
}

var sourceSpan = length == items.Length
? new ReadOnlySpan<T>(items)
: new ReadOnlySpan<T>(items, 0, length);

var destSpan = new Span<T>(array, arrayIndex, array.Length - arrayIndex);
InnerAsSpan().CopyTo(destSpan);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
ReadOnlySpan<T> InnerAsSpan()
{
Debug.Assert(length != default);

sourceSpan.CopyTo(destSpan);
return length == items.Length
? new ReadOnlySpan<T>(items)
: new ReadOnlySpan<T>(items, 0, length);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit f8d8b03

Please sign in to comment.