Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pooled StringBuilder #5665

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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