Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -25,8 +24,6 @@ public ByteArrayContent(byte[] content)
_content = content;
_offset = 0;
_count = content.Length;

SetBuffer(_content, _offset, _count);
}

public ByteArrayContent(byte[] content, int offset, int count)
Expand All @@ -47,8 +44,6 @@ public ByteArrayContent(byte[] content, int offset, int count)
_content = content;
_offset = offset;
_count = count;

SetBuffer(_content, _offset, _count);
}

protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ private bool IsBuffered
get { return _bufferedContent != null; }
}

internal void SetBuffer(byte[] buffer, int offset, int count)
{
_bufferedContent = new MemoryStream(buffer, offset, count, writable: false, publiclyVisible: true);
}

internal bool TryGetBuffer(out ArraySegment<byte> buffer)
{
if (_bufferedContent != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -13,16 +12,8 @@ public sealed class ReadOnlyMemoryContent : HttpContent
{
private readonly ReadOnlyMemory<byte> _content;

public ReadOnlyMemoryContent(ReadOnlyMemory<byte> content)
{
public ReadOnlyMemoryContent(ReadOnlyMemory<byte> content) =>
_content = content;
if (MemoryMarshal.TryGetArray(content, out ArraySegment<byte> array))
{
// If we have an array, allow HttpClient to take optimized paths by just
// giving it the array content to use as its already buffered data.
SetBuffer(array.Array!, array.Offset, array.Count);
}
}

protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) =>
stream.WriteAsync(_content).AsTask();
Expand Down