Skip to content

Commit 2131f6f

Browse files
committed
tweaks
1 parent 0a91ce7 commit 2131f6f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/MemoryPack.Core/Compression/BrotliCompressor.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,20 @@ public async ValueTask CopyToAsync(Stream stream, int bufferSize = 65535, Cancel
151151

152152
using var encoder = new BrotliEncoder(quality, window);
153153

154+
foreach (var item in bufferWriter)
155+
{
156+
if (item.Length > bufferSize)
157+
{
158+
bufferSize = item.Length;
159+
}
160+
}
161+
154162
var buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
155163
try
156164
{
157165
foreach (var item in bufferWriter)
158166
{
159167
var source = item;
160-
if (source.Length > buffer.Length)
161-
{
162-
ArrayPool<byte>.Shared.Return(buffer);
163-
buffer = ArrayPool<byte>.Shared.Rent(source.Length);
164-
}
165168
var lastResult = OperationStatus.DestinationTooSmall;
166169
while (lastResult == OperationStatus.DestinationTooSmall)
167170
{

0 commit comments

Comments
 (0)