Skip to content

Commit 6e7c63a

Browse files
committed
Use span instead of memory
1 parent 19028cd commit 6e7c63a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Middleware/ResponseCaching/src/CacheEntry/CachedResponseBody.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@ public async Task CopyToAsync(PipeWriter destination, CancellationToken cancella
3131
foreach (var segment in Segments)
3232
{
3333
cancellationToken.ThrowIfCancellationRequested();
34-
var segmentLength = segment.Length;
3534

36-
var memory = destination.GetMemory(segmentLength);
37-
segment.AsMemory().CopyTo(memory);
38-
39-
destination.Advance(segmentLength);
35+
Copy(segment, destination);
4036

4137
await destination.FlushAsync();
4238
}
39+
}
40+
41+
private static void Copy(byte[] segment, PipeWriter destination)
42+
{
43+
var segmentLength = segment.Length;
44+
var span = destination.GetSpan(segmentLength);
4345

44-
await destination.CompleteAsync();
46+
segment.CopyTo(span);
47+
destination.Advance(segmentLength);
4548
}
4649
}
4750
}

0 commit comments

Comments
 (0)