Skip to content

Commit 28c5775

Browse files
authored
Reduce allocations in AnalyzerConfig.UnescapeSectionName (#80288)
* Reduce allocations in AnalyzerConfig.UnescapeSectionName Just a simple switch to using a pooled StringBuilder. Not a huge allocator, but easy enough to switch.
1 parent 49081fb commit 28c5775

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Compilers/Core/Portable/CommandLine/AnalyzerConfig.SectionNameMatching.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public bool IsMatch(string s)
123123

124124
internal static string UnescapeSectionName(string sectionName)
125125
{
126-
var sb = new StringBuilder();
126+
var pooledStrbuilder = PooledStringBuilder.GetInstance();
127+
StringBuilder sb = pooledStrbuilder.Builder;
127128
SectionNameLexer lexer = new SectionNameLexer(sectionName);
128129
while (!lexer.IsDone)
129130
{
@@ -139,7 +140,7 @@ internal static string UnescapeSectionName(string sectionName)
139140
throw ExceptionUtilities.UnexpectedValue(tokenKind);
140141
}
141142
}
142-
return sb.ToString();
143+
return pooledStrbuilder.ToStringAndFree();
143144
}
144145

145146
/// <summary>

0 commit comments

Comments
 (0)