Skip to content

Commit a0bfa97

Browse files
nareshjoNaresh Joshi
andauthored
Reduce allocation in DownloadTimeoutStream.ReadAsync caused by avoidable string formatting/allocations (#7035)
Co-authored-by: Naresh Joshi <[email protected]>
1 parent fa19202 commit a0bfa97

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/NuGet.Core/NuGet.Protocol/Utility/DownloadTimeoutStream.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ public override async Task<int> ReadAsync(
7171
int count,
7272
CancellationToken cancellationToken)
7373
{
74-
var timeoutMessage = string.Format(
75-
CultureInfo.CurrentCulture,
76-
Strings.Error_DownloadTimeout,
77-
_downloadName,
78-
_timeout.TotalMilliseconds);
79-
8074
try
8175
{
8276
var result = await TimeoutUtility.StartWithTimeout(
@@ -89,6 +83,12 @@ public override async Task<int> ReadAsync(
8983
}
9084
catch (TimeoutException e)
9185
{
86+
var timeoutMessage = string.Format(
87+
CultureInfo.CurrentCulture,
88+
Strings.Error_DownloadTimeout,
89+
_downloadName,
90+
_timeout.TotalMilliseconds);
91+
9292
// Failed stream operations should throw an IOException.
9393
throw new IOException(timeoutMessage, e);
9494
}

0 commit comments

Comments
 (0)