Skip to content

Commit f8494e6

Browse files
committed
Only copy necessary entries
1 parent 889e3e7 commit f8494e6

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- When growing only copy written content to the new buffer and safe some bytes
12+
913
## [1.10.4] - 2022-12-27
1014

1115
### Fixed

src/LinkDotNet.StringBuilder/TypedSpanList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private void Grow(int capacity = 0)
4646
var currentSize = buffer.Length;
4747
var newSize = capacity > 0 ? capacity : currentSize * 2;
4848
var rented = GC.AllocateUninitializedArray<T>(newSize);
49-
buffer.CopyTo(rented);
49+
buffer[..count].CopyTo(rented);
5050
buffer = rented;
5151
}
5252
}

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private void Grow(int capacity = 0)
294294

295295
var newSize = capacity > currentSize ? capacity : currentSize * 2;
296296
var rented = ArrayPool<char>.Shared.Rent(newSize);
297-
buffer.CopyTo(rented);
297+
buffer[..bufferPosition].CopyTo(rented);
298298
var oldBufferFromPool = arrayFromPool;
299299
buffer = arrayFromPool = rented;
300300

0 commit comments

Comments
 (0)