Skip to content

Commit

Permalink
Remove ClientArrayPool
Browse files Browse the repository at this point in the history
Fixes #1421
  • Loading branch information
lukebakken committed Mar 11, 2024
1 parent 0682db6 commit f9dd5c6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 123 deletions.
114 changes: 0 additions & 114 deletions projects/RabbitMQ.Client/client/ClientArrayPool.cs

This file was deleted.

3 changes: 2 additions & 1 deletion projects/RabbitMQ.Client/client/RentedMemory.cs
Expand Up @@ -30,6 +30,7 @@
//---------------------------------------------------------------------------

using System;
using System.Buffers;

namespace RabbitMQ.Client
{
Expand Down Expand Up @@ -73,7 +74,7 @@ private void Dispose(bool disposing)
{
if (disposing && RentedArray != null)
{
ClientArrayPool.Return(RentedArray);
ArrayPool<byte>.Shared.Return(RentedArray);
}

_disposedValue = true;
Expand Down
3 changes: 2 additions & 1 deletion projects/RabbitMQ.Client/client/impl/CommandAssembler.cs
Expand Up @@ -30,6 +30,7 @@
//---------------------------------------------------------------------------

using System;
using System.Buffers;
using RabbitMQ.Client.client.framing;
using RabbitMQ.Client.Exceptions;
using RabbitMQ.Client.Framing.Impl;
Expand Down Expand Up @@ -185,7 +186,7 @@ private bool ParseBodyFrame(in InboundFrame frame)
}

// Is returned by IncomingCommand.ReturnPayload in Session.HandleFrame
_rentedBodyArray = ClientArrayPool.Rent(_remainingBodyByteCount);
_rentedBodyArray = ArrayPool<byte>.Shared.Rent(_remainingBodyByteCount);
_bodyMemory = new ReadOnlyMemory<byte>(_rentedBodyArray, 0, _remainingBodyByteCount);
}

Expand Down
12 changes: 6 additions & 6 deletions projects/RabbitMQ.Client/client/impl/Frame.cs
Expand Up @@ -143,7 +143,7 @@ internal static class Heartbeat
public static RentedMemory GetHeartbeatFrame()
{
// Is returned by SocketFrameHandler.WriteLoop
byte[] buffer = ClientArrayPool.Rent(FrameSize);
byte[] buffer = ArrayPool<byte>.Shared.Rent(FrameSize);
Payload.CopyTo(buffer);
var mem = new ReadOnlyMemory<byte>(buffer, 0, FrameSize);
return new RentedMemory(mem, buffer);
Expand All @@ -157,7 +157,7 @@ public static RentedMemory SerializeToFrames<T>(ref T method, ushort channelNumb
int size = Method.FrameSize + method.GetRequiredBufferSize();

// Will be returned by SocketFrameWriter.WriteLoop
byte[] array = ClientArrayPool.Rent(size);
byte[] array = ArrayPool<byte>.Shared.Rent(size);
int offset = Method.WriteTo(array, channelNumber, ref method);

System.Diagnostics.Debug.Assert(offset == size, $"Serialized to wrong size, expect {size}, offset {offset}");
Expand All @@ -176,7 +176,7 @@ public static RentedMemory SerializeToFrames<T>(ref T method, ushort channelNumb
BodySegment.FrameSize * GetBodyFrameCount(maxBodyPayloadBytes, remainingBodyBytes) + remainingBodyBytes;

// Will be returned by SocketFrameWriter.WriteLoop
byte[] array = ClientArrayPool.Rent(size);
byte[] array = ArrayPool<byte>.Shared.Rent(size);

int offset = Method.WriteTo(array, channelNumber, ref method);
offset += Header.WriteTo(array.AsSpan(offset), channelNumber, ref header, remainingBodyBytes);
Expand Down Expand Up @@ -342,14 +342,14 @@ internal static bool TryReadFrame(ref ReadOnlySequence<byte> buffer, uint maxMes
}
else
{
byte[] payloadBytes = ClientArrayPool.Rent(readSize);
byte[] payloadBytes = ArrayPool<byte>.Shared.Rent(readSize);
ReadOnlySequence<byte> framePayload = buffer.Slice(7, readSize);
framePayload.CopyTo(payloadBytes);

if (payloadBytes[payloadSize] != Constants.FrameEnd)
{
byte frameEndMarker = payloadBytes[payloadSize];
ClientArrayPool.Return(payloadBytes);
ArrayPool<byte>.Shared.Return(payloadBytes);
throw new MalformedFrameException($"Bad frame end marker: {frameEndMarker}");
}

Expand All @@ -368,7 +368,7 @@ public byte[] TakeoverPayload()

public void ReturnPayload()
{
ClientArrayPool.Return(_rentedArray);
ArrayPool<byte>.Shared.Return(_rentedArray);
}

public override string ToString()
Expand Down
3 changes: 2 additions & 1 deletion projects/Test/Unit/TestFrameFormatting.cs
Expand Up @@ -30,6 +30,7 @@
//---------------------------------------------------------------------------

using System;
using System.Buffers;
using RabbitMQ.Client;
using RabbitMQ.Client.Framing.Impl;
using RabbitMQ.Client.Impl;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void HeartbeatFrame()
}
finally
{
ClientArrayPool.Return(sfc.RentedArray);
ArrayPool<byte>.Shared.Return(sfc.RentedArray);
}
}

Expand Down

0 comments on commit f9dd5c6

Please sign in to comment.