Skip to content

Commit b5ef20f

Browse files
committed
Don't overgrow buffer
1 parent a5908a7 commit b5ef20f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void Append(bool value)
1515
// So we can check if we have enough space in the buffer
1616
if (bufferPosition + 5 > buffer.Length)
1717
{
18-
Grow(bufferPosition * 2);
18+
Grow(bufferPosition);
1919
}
2020

2121
if (!value.TryFormat(buffer[bufferPosition..], out var charsWritten))
@@ -48,7 +48,7 @@ public void Append(scoped ReadOnlySpan<char> str)
4848
var newSize = str.Length + bufferPosition;
4949
if (newSize > buffer.Length)
5050
{
51-
Grow(newSize * 2);
51+
Grow(newSize);
5252
}
5353

5454
str.CopyTo(buffer[bufferPosition..]);

src/LinkDotNet.StringBuilder/ValueStringBuilder.Insert.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Insert(int index, scoped ReadOnlySpan<char> value)
4545
var newLength = bufferPosition + value.Length;
4646
if (newLength > buffer.Length)
4747
{
48-
Grow(newLength * 2);
48+
Grow(newLength);
4949
}
5050

5151
bufferPosition = newLength;
@@ -79,7 +79,7 @@ private void InsertSpanFormattable<T>(int index, T value, ReadOnlySpan<char> for
7979
var newLength = bufferPosition + written;
8080
if (newLength > buffer.Length)
8181
{
82-
Grow(newLength * 2);
82+
Grow(newLength);
8383
}
8484

8585
bufferPosition = newLength;

0 commit comments

Comments
 (0)