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 c062c54
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 27 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Microsoft.AspNetCore.Routing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a
Microsoft.AspNetCore.Routing.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Microsoft.Extensions.Primitives, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Microsoft.Net.Http.Headers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
System.Collections, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Collections.Concurrent, Version=4.0.15.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Collections.NonGeneric, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Expand Down

0 comments on commit c062c54

Please sign in to comment.