Skip to content

Commit

Permalink
Use pooled StringBuilder (#5665)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erarndt authored Mar 4, 2024
1 parent 646f252 commit 34f9e1a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public virtual string GetShortFolderName(IFrameworkNameProvider mappings)
// Check for rewrites
var framework = mappings.GetShortNameReplacement(this);

var sb = new StringBuilder();
var sb = StringBuilderPool.Shared.Rent(256);

if (IsSpecificFramework)
{
Expand Down Expand Up @@ -292,12 +292,13 @@ public virtual string GetShortFolderName(IFrameworkNameProvider mappings)
sb.Append(Framework);
}

return sb.ToString().ToLowerInvariant();
return StringBuilderPool.Shared.ToStringAndReturn(sb).ToLowerInvariant();
}

private static string GetDisplayVersion(Version version)
{
var sb = new StringBuilder(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor));
var sb = StringBuilderPool.Shared.Rent(256);
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor);

if (version.Build > 0
|| version.Revision > 0)
Expand All @@ -310,7 +311,7 @@ private static string GetDisplayVersion(Version version)
}
}

return sb.ToString();
return StringBuilderPool.Shared.ToStringAndReturn(sb);
}

private static string GetLettersAndDigitsOnly(string s)
Expand Down

0 comments on commit 34f9e1a

Please sign in to comment.