Skip to content

Commit

Permalink
Remove usage of ArrayPool from ChunkedEncodingReadStream
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Feb 28, 2024
1 parent 04df98d commit aa4a106
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@
<assembly fullname="StackExchange.Redis" />
<assembly fullname="StackExchange.Redis.StrongName" />
<assembly fullname="System" />
<assembly fullname="System.Buffers">
<type fullname="System.Buffers.ArrayPool`1" />
</assembly>
<assembly fullname="System.Collections">
<type fullname="System.Collections.BitArray" />
<type fullname="System.Collections.Generic.Comparer`1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
using System.Threading.Tasks;
using Datadog.Trace.Util.Streams;

#if NETCOREAPP
using ArrayPool = System.Buffers.ArrayPool<byte>;
#else
using ArrayPool = Datadog.Trace.VendoredMicrosoftCode.System.Buffers.ArrayPool<byte>;
#endif

namespace Datadog.Trace.HttpOverStreams;

internal sealed partial class ChunkedEncodingReadStream : DelegatingStream
Expand All @@ -45,8 +39,6 @@ internal sealed partial class ChunkedEncodingReadStream : DelegatingStream
128;
#endif

private static readonly ArrayPool Pool = ArrayPool.Shared;

private readonly Stream _innerStream;
private readonly byte[] _streamBuffer;
private ulong _bytesRemainingInChunk;
Expand All @@ -63,7 +55,7 @@ public ChunkedEncodingReadStream(Stream innerStream)
_innerStream = innerStream;
// We use a buffer that is double the size of the read buffer, so that we can move
// the bytes around if we end up hitting edge cases
_streamBuffer = Pool.Rent(ReadBufferSize * 2);
_streamBuffer = new byte[ReadBufferSize * 2];
_currentPosition = new(offset: 0, count: 0);
}

Expand All @@ -77,20 +69,6 @@ private enum ParsingState : byte
Done
}

protected override void Dispose(bool disposing)
{
Pool.Return(_streamBuffer);
base.Dispose(disposing);
}

#if NETCOREAPP
public override ValueTask DisposeAsync()
{
Pool.Return(_streamBuffer);
return base.DisposeAsync();
}
#endif

// This is not called by our production code, so we're yolo-ing it
// MockTracerAgent currently _does_ use this code path
public override int Read(byte[] buffer, int offset, int count)
Expand Down

0 comments on commit aa4a106

Please sign in to comment.