Skip to content

Commit fa3bc0f

Browse files
committed
Fix optimization not returning to pool
1 parent c69b317 commit fa3bc0f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ public void EnsureCapacity(int newCapacity)
184184

185185
int newSize = FindSmallestPowerOf2Above(newCapacity);
186186

187-
Span<char> rented = ArrayPool<char>.Shared.Rent(newSize);
187+
char[] rented = ArrayPool<char>.Shared.Rent(newSize);
188188

189189
if (bufferPosition > 0)
190190
{
191191
ref char sourceRef = ref MemoryMarshal.GetReference(buffer);
192-
ref char destinationRef = ref MemoryMarshal.GetReference(rented);
192+
ref char destinationRef = ref MemoryMarshal.GetReference(rented.AsSpan());
193193

194194
Unsafe.CopyBlock(
195195
ref Unsafe.As<char, byte>(ref destinationRef),
@@ -203,6 +203,7 @@ ref Unsafe.As<char, byte>(ref sourceRef),
203203
}
204204

205205
buffer = rented;
206+
arrayFromPool = rented;
206207
}
207208

208209
/// <summary>

0 commit comments

Comments
 (0)