Skip to content

Commit ba3e7a2

Browse files
committed
Remove redundant null check
1 parent b54c41d commit ba3e7a2

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

CHANGELOG.md

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

99
## [1.8.0] - 2022-11-15
1010

11+
### Changed
12+
13+
- Slight improvement when appending nullable types to the string builder
14+
1115
### Added
1216

1317
- implicit cast operator from `string` and `ReadOnlySpan<char>` to the `ValueStringBuilder` with pre-initialized buffer

src/LinkDotNet.StringBuilder/ValueStringBuilder.AppendJoin.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ private void AppendJoinInternalString<T2>(ReadOnlySpan<char> separator, IEnumera
6464
{
6565
Append(separator);
6666
current = enumerator.Current;
67-
if (current != null)
68-
{
69-
AppendInternal(current);
70-
}
67+
AppendInternal(current);
7168
}
7269
}
7370

@@ -93,10 +90,7 @@ private void AppendJoinInternalChar<T2>(char separator, IEnumerable<T2> values)
9390
{
9491
AppendInternal(separator);
9592
current = enumerator.Current;
96-
if (current != null)
97-
{
98-
AppendInternal(current);
99-
}
93+
AppendInternal(current);
10094
}
10195
}
10296

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilder.AppendJoin.Tests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ public static IEnumerable<object[]> StringSeparatorTestData()
1010
yield return new object[] { ",", new[] { "Hello", "World" }, "Hello,World" };
1111
yield return new object[] { ",", new[] { "Hello" }, "Hello" };
1212
yield return new object[] { ",", Array.Empty<string>(), string.Empty };
13+
yield return new object[] { ",", new string?[] { null }, string.Empty };
1314
}
1415

1516
public static IEnumerable<object[]> CharSeparatorTestData()
1617
{
1718
yield return new object[] { ',', new[] { "Hello", "World" }, "Hello,World" };
1819
yield return new object[] { ',', new[] { "Hello" }, "Hello" };
1920
yield return new object[] { ',', Array.Empty<string>(), string.Empty };
21+
yield return new object[] { ',', new string?[] { null }, string.Empty };
2022
}
2123

2224
[Theory]
@@ -46,18 +48,18 @@ public void ShouldAddDataWithStringSeparator()
4648
{
4749
using var stringBuilder = new ValueStringBuilder();
4850

49-
stringBuilder.AppendJoin(",", new object[] { 1, new DateTime(1900, 1, 1) });
51+
stringBuilder.AppendJoin(",", new object[] { 1, 1.05f });
5052

51-
stringBuilder.ToString().Should().Be("1,01/01/1900 00:00:00");
53+
stringBuilder.ToString().Should().Be("1,1.05");
5254
}
5355

5456
[Fact]
5557
public void ShouldAddDataWithCharSeparator()
5658
{
5759
using var stringBuilder = new ValueStringBuilder();
5860

59-
stringBuilder.AppendJoin(',', new object[] { 1, new DateTime(1900, 1, 1) });
61+
stringBuilder.AppendJoin(',', new object[] { 1, 1.05f });
6062

61-
stringBuilder.ToString().Should().Be("1,01/01/1900 00:00:00");
63+
stringBuilder.ToString().Should().Be("1,1.05");
6264
}
6365
}

0 commit comments

Comments
 (0)