Skip to content

Commit 1587fc9

Browse files
author
LinkDotNet Bot
committed
Updating to newest release
2 parents b7cd571 + 65db5bd commit 1587fc9

File tree

7 files changed

+43
-6
lines changed

7 files changed

+43
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
66

77
## [Unreleased]
88

9+
## [1.22.0] - 2024-12-18
10+
11+
### Added
12+
13+
- `AppendSpan` method
14+
915
## [1.21.1] - 2024-11-08
1016

1117
### Changed
@@ -412,7 +418,8 @@ This release brings extensions to the `ValueStringBuilder` API. For `v1.0` the `
412418

413419
- Initial release
414420

415-
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/1.21.1...HEAD
421+
[unreleased]: https://github.com/linkdotnet/StringBuilder/compare/1.22.0...HEAD
422+
[1.22.0]: https://github.com/linkdotnet/StringBuilder/compare/1.21.1...1.22.0
416423
[1.21.1]: https://github.com/linkdotnet/StringBuilder/compare/1.21.0...1.21.1
417424
[1.21.0]: https://github.com/linkdotnet/StringBuilder/compare/1.20.0...1.21.0
418425
[1.20.0]: https://github.com/linkdotnet/StringBuilder/compare/1.19.1...1.20.0

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4-
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.32.0.97167">
4+
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.3.0.106239">
55
<PrivateAssets>all</PrivateAssets>
66
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
77
</PackageReference>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The blog goes into a bit more in detail about how it works with a simplistic ver
3838
The library is not meant as a general replacement for the `StringBuilder` shipped with the .net framework itself. You can head over to the documentation and read about the ["Known limitations"](https://linkdotnet.github.io/StringBuilder/articles/known_limitations.html).
3939
The library works best for a small to medium amount of strings (not multiple 100'000 characters, even though it can be still faster and uses fewer allocations). At any time, you can convert the `ValueStringBuilder` to a "normal" `StringBuilder` and vice versa.
4040

41-
The normal use case is to add concatenate strings in a hot path where the goal is to put as minimal pressure on the GC as possible.
41+
The normal use case is to concatenate strings in a hot path where the goal is to put as minimal pressure on the GC as possible.
4242

4343
## Documentation
4444
More detailed documentation can be found [here](https://linkdotnet.github.io/StringBuilder/). It is really important to understand how the `ValueStringBuilder` works so that you did not run into weird situations where performance/allocations can even rise.

src/LinkDotNet.StringBuilder/LinkDotNet.StringBuilder.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</PropertyGroup>
4141

4242
<ItemGroup>
43-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.177">
43+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.182">
4444
<PrivateAssets>all</PrivateAssets>
4545
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4646
</PackageReference>

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ public void AppendLine(scoped ReadOnlySpan<char> str)
136136
Append(string.Concat(str, Environment.NewLine));
137137
}
138138

139+
/// <summary>
140+
/// Increases the size of the string builder returning a span of the length appended.
141+
/// </summary>
142+
/// <param name="length">Integer representing the length to be appended.</param>
143+
/// <returns>A span with the characters appended.</returns>
144+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
145+
public Span<char> AppendSpan(int length)
146+
{
147+
int origPos = bufferPosition;
148+
if (origPos > buffer.Length - length)
149+
{
150+
Grow(length);
151+
}
152+
153+
bufferPosition = origPos + length;
154+
return buffer.Slice(origPos, length);
155+
}
156+
139157
[MethodImpl(MethodImplOptions.AggressiveInlining)]
140158
private void AppendSpanFormattable<T>(T value, ReadOnlySpan<char> format = default, int bufferSize = 36)
141159
where T : ISpanFormattable

tests/LinkDotNet.StringBuilder.UnitTests/LinkDotNet.StringBuilder.UnitTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="FluentAssertions" Version="6.12.1" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
11+
<PackageReference Include="FluentAssertions" Version="6.12.2" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1313
<PackageReference Include="xunit" Version="2.9.2" />
1414
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ public void ShouldAppendLine()
4747
stringBuilder.ToString().Should().Contain("Hello").And.Contain(Environment.NewLine);
4848
}
4949

50+
[Fact]
51+
public void ShouldAppendSpan()
52+
{
53+
using var stringBuilder = new ValueStringBuilder();
54+
55+
var returned = stringBuilder.AppendSpan(2);
56+
57+
stringBuilder.Length.Should().Be(2);
58+
59+
stringBuilder.ToString().Should().Be(returned.ToString());
60+
}
61+
5062
[Fact]
5163
public void ShouldOnlyAddNewline()
5264
{

0 commit comments

Comments
 (0)