Skip to content

Commit d2b9f35

Browse files
Joy-lesslinkdotnet
authored andcommitted
Short-circuit empty span
1 parent 7a93115 commit d2b9f35

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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)