Skip to content

Commit 77e82d9

Browse files
committed
Ensure capacity before pinning span.
1 parent 6fbc1b1 commit 77e82d9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/TextTools/StringBuilderSpanExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public static StringBuilder Append(this StringBuilder builder, ReadOnlySpan<char
1919
#if NET || NETSTANDARD2_1_OR_GREATER
2020
return builder.Append(span);
2121
#else
22+
// Ensure there will be enough capacity for the span before pinning,
23+
// to reduce the risk of triggering a GC while span is pinned.
24+
builder.EnsureCapacity(builder.Length + span.Length);
25+
2226
unsafe
2327
{
2428
fixed (char* ptr = span)

0 commit comments

Comments
 (0)