Skip to content

Commit 704fed2

Browse files
authored
Merge branch 'main' into add-equals-stringcomparison
2 parents dff02a5 + 07afdad commit 704fed2

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
1313
### Changed
1414

1515
- Improved `Equals(ReadOnlySpan<char>)` (by @Joy-less in #234)
16+
- Added performance short-circuit when span is empty in `Append(ReadOnlySpan<char>)`, `AppendSpan(int)`, `Insert(int, ReadOnlySpan<char>)` in #233 (by @Joy-less)
1617

1718
## [2.2.0] - 2025-01-25
1819

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

+10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public void Append<T>(T value, ReadOnlySpan<char> format = default, int bufferSi
6464
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6565
public void Append(scoped ReadOnlySpan<char> str)
6666
{
67+
if (str.IsEmpty)
68+
{
69+
return;
70+
}
71+
6772
var newSize = str.Length + bufferPosition;
6873
if (newSize > buffer.Length)
6974
{
@@ -160,6 +165,11 @@ public void AppendLine(scoped ReadOnlySpan<char> str)
160165
[MethodImpl(MethodImplOptions.AggressiveInlining)]
161166
public Span<char> AppendSpan(int length)
162167
{
168+
if (length == 0)
169+
{
170+
return [];
171+
}
172+
163173
var origPos = bufferPosition;
164174
if (origPos > buffer.Length - length)
165175
{

src/LinkDotNet.StringBuilder/ValueStringBuilder.Insert.cs

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public void Insert(int index, scoped ReadOnlySpan<char> value)
6666
throw new ArgumentOutOfRangeException(nameof(index), "The given index can't be bigger than the string itself.");
6767
}
6868

69+
if (value.IsEmpty)
70+
{
71+
return;
72+
}
73+
6974
var newLength = bufferPosition + value.Length;
7075
if (newLength > buffer.Length)
7176
{

0 commit comments

Comments
 (0)