Optimize 'Span.Content' memory allocation
This commit is contained in:
parent
6b075880ce
commit
e9a688be15
|
|
@ -42,14 +42,23 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
{
|
{
|
||||||
if (_content == null)
|
if (_content == null)
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder();
|
var symbolCount = Symbols.Count;
|
||||||
for (var i = 0; i < Symbols.Count; i++)
|
if (symbolCount == 1)
|
||||||
{
|
{
|
||||||
var symbol = Symbols[i];
|
// Perf: no StringBuilder allocation if not necessary
|
||||||
builder.Append(symbol.Content);
|
_content = Symbols[0].Content;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
for (var i = 0; i < symbolCount; i++)
|
||||||
|
{
|
||||||
|
var symbol = Symbols[i];
|
||||||
|
builder.Append(symbol.Content);
|
||||||
|
}
|
||||||
|
|
||||||
_content = builder.ToString();
|
_content = builder.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _content;
|
return _content;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue