Skip to content

Commit 48f5961

Browse files
authored
reduce number of allocations. (Azure#21243)
1 parent e943412 commit 48f5961

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,8 +1629,6 @@ internal async Task<Response<BlobContentInfo>> StagedUploadInternal(
16291629
.ClientSideEncryptInternal(content, options.Metadata, async, cancellationToken).ConfigureAwait(false);
16301630
}
16311631

1632-
var client = new BlockBlobClient(Uri, ClientConfiguration);
1633-
16341632
var uploader = GetPartitionedUploader(
16351633
transferOptions: options?.TransferOptions ?? default,
16361634
operationName: $"{nameof(BlobClient)}.{nameof(Upload)}");
@@ -1710,11 +1708,24 @@ internal async Task<Response<BlobContentInfo>> StagedUploadInternal(
17101708
}
17111709
#endregion Upload
17121710

1711+
private BlockBlobClient _blockBlobClient;
1712+
1713+
private BlockBlobClient BlockBlobClient
1714+
{
1715+
get
1716+
{
1717+
if (_blockBlobClient == null)
1718+
{
1719+
_blockBlobClient = new BlockBlobClient(Uri, ClientConfiguration);
1720+
}
1721+
return _blockBlobClient;
1722+
}
1723+
}
1724+
17131725
internal PartitionedUploader<BlobUploadOptions, BlobContentInfo> GetPartitionedUploader(
17141726
StorageTransferOptions transferOptions,
17151727
ArrayPool<byte> arrayPool = null,
17161728
string operationName = null)
1717-
=> new BlockBlobClient(Uri, ClientConfiguration)
1718-
.GetPartitionedUploader(transferOptions, arrayPool, operationName);
1729+
=> BlockBlobClient.GetPartitionedUploader(transferOptions, arrayPool, operationName);
17191730
}
17201731
}

0 commit comments

Comments
 (0)