Skip to content

Commit dc89ecd

Browse files
author
krivchenko-kv
committed
S3Upload little fix
1 parent b790eeb commit dc89ecd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Storage/S3Upload.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ public sealed class S3Upload : IDisposable
1414
private byte[]? _byteBuffer;
1515
private bool _disposed;
1616
private int _partCount;
17+
private readonly IArrayPool _arrayPool;
1718
private string[] _parts;
1819

20+
1921
internal S3Upload(S3BucketClient client, string fileName, string encodedFileName, string uploadId)
2022
{
2123
FileName = fileName;
@@ -24,7 +26,8 @@ internal S3Upload(S3BucketClient client, string fileName, string encodedFileName
2426
_client = client;
2527
_encodedFileName = encodedFileName;
2628

27-
_parts = DefaultArrayPool.Instance.Rent<string>(16);
29+
_arrayPool = DefaultArrayPool.Instance;
30+
_parts = _arrayPool.Rent<string>(16);
2831
}
2932

3033
/// <summary>
@@ -125,7 +128,7 @@ public async Task<bool> AddPart(byte[] data, int length, CancellationToken ct)
125128
/// <returns>Возвращает результат загрузки</returns>
126129
public async Task<bool> AddParts(Stream data, CancellationToken ct)
127130
{
128-
_byteBuffer ??= DefaultArrayPool.Instance.Rent<byte>(S3BucketClient.DefaultPartSize);
131+
_byteBuffer ??= _arrayPool.Rent<byte>(S3BucketClient.DefaultPartSize);
129132

130133
while (true)
131134
{
@@ -197,12 +200,12 @@ public void Dispose()
197200
}
198201

199202
Array.Clear(_parts, 0, _partCount);
200-
DefaultArrayPool.Instance.Return(_parts);
203+
_arrayPool.Return(_parts);
201204
_parts = null!;
202205

203206
if (_byteBuffer is not null)
204207
{
205-
DefaultArrayPool.Instance.Return(_byteBuffer);
208+
_arrayPool.Return(_byteBuffer);
206209
_byteBuffer = null;
207210
}
208211

0 commit comments

Comments
 (0)