Fix resize logic in StringBuffer.
This commit is contained in:
@@ -410,8 +410,16 @@ namespace System.Text.Formatting {
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void CheckCapacity (int count) {
|
||||
if (currentCount + count > buffer.Length)
|
||||
Array.Resize(ref buffer, buffer.Length * 2);
|
||||
int newCount = currentCount + count;
|
||||
if (newCount > buffer.Length) {
|
||||
int newCapacity = buffer.Length * 2;
|
||||
if (newCapacity < newCount) newCapacity = newCount;
|
||||
char[] newBuffer = new char[newCapacity];
|
||||
fixed (void* nptr = newBuffer, ptr = buffer) {
|
||||
Unsafe.CopyBlock(nptr, ptr, (uint)(currentCount * sizeof(char)));
|
||||
}
|
||||
buffer = newBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
bool AppendSegment<T>(ref char* currRef, char* end, char* dest, ref int prevArgIndex, ref T args) where T : IArgSet {
|
||||
|
Reference in New Issue
Block a user