Skip to content

Commit eaefe7a

Browse files
authored
Reduce allocations in MakeArrayFormatter (#52675)
JsonEncodedText is a struct. Passing it into StringBuilder.Append will box the value into an object, just to call ToString() on it. Instead, grab the Value string from the JsonEncodedText and pass the string into StringBuilder.Append, so nothing is boxed.
1 parent 0193e8a commit eaefe7a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Components/Components/src/BindConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,13 +1810,13 @@ private static class FormatterDelegateCache
18101810
}
18111811

18121812
var builder = new StringBuilder("[\"");
1813-
builder.Append(JsonEncodedText.Encode(elementFormatter(value[0], culture)?.ToString() ?? string.Empty));
1813+
builder.Append(JsonEncodedText.Encode(elementFormatter(value[0], culture)?.ToString() ?? string.Empty).Value);
18141814
builder.Append('\"');
18151815

18161816
for (var i = 1; i < value.Length; i++)
18171817
{
18181818
builder.Append(", \"");
1819-
builder.Append(JsonEncodedText.Encode(elementFormatter(value[i], culture)?.ToString() ?? string.Empty));
1819+
builder.Append(JsonEncodedText.Encode(elementFormatter(value[i], culture)?.ToString() ?? string.Empty).Value);
18201820
builder.Append('\"');
18211821
}
18221822

0 commit comments

Comments
 (0)