Reduce overhead of ReadOnlySequence<T>.CopyTo (dotnet/corefx#35819)
authorStephen Toub <stoub@microsoft.com>
Wed, 6 Mar 2019 19:10:46 +0000 (11:10 -0800)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2019 19:10:46 +0000 (11:10 -0800)
commit8e91ff8699ef09913b24e3be9ad2649972e1d367
tree1ef0155140472428b7221187e18f5c46656380d8
parentaf1ceb31a082e19374597912592a93c2b3dd255c
Reduce overhead of ReadOnlySequence<T>.CopyTo (dotnet/corefx#35819)

`ReadOnlySequence<T>.Length` isn't as small or fast as `ReadOnlySpan<T>.Length`, which is just a field access.  Since we need the span anyway for the single element case, just get the span first and then compare with its length.

Commit migrated from https://github.com/dotnet/corefx/commit/7fc9d5730aabc6724edf18f5bedde6d32610f681
src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs