File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
src/LinkDotNet.StringBuilder Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff 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+ - Optimized ` Append(scoped ReadOnlySpan<char>) ` to be roughly 5% faster.
12+
913## [ 1.18.3] - 2023-09-22
1014
1115### Changed
Original file line number Diff line number Diff line change 11using System . Runtime . CompilerServices ;
2+ using System . Runtime . InteropServices ;
23
34namespace LinkDotNet . StringBuilder ;
45
@@ -51,7 +52,13 @@ public void Append(scoped ReadOnlySpan<char> str)
5152 Grow ( newSize ) ;
5253 }
5354
54- str . CopyTo ( buffer [ bufferPosition ..] ) ;
55+ ref var strRef = ref MemoryMarshal . GetReference ( str ) ;
56+ ref var bufferRef = ref MemoryMarshal . GetReference ( buffer [ bufferPosition ..] ) ;
57+ Unsafe . CopyBlock (
58+ ref Unsafe . As < char , byte > ( ref bufferRef ) ,
59+ ref Unsafe . As < char , byte > ( ref strRef ) ,
60+ ( uint ) ( str . Length * sizeof ( char ) ) ) ;
61+
5562 bufferPosition += str . Length ;
5663 }
5764
You can’t perform that action at this time.
0 commit comments