Skip to content

Commit abb1ef4

Browse files
author
LinkDotNet Bot
committed
Updating to newest release
2 parents 3a817c4 + 956be64 commit abb1ef4

File tree

12 files changed

+63
-17
lines changed

12 files changed

+63
-17
lines changed

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
steps:
2424
- name: Checkout repository
25-
uses: actions/[email protected].0
25+
uses: actions/[email protected].1
2626

2727
- uses: actions/[email protected]
2828
with:

.github/workflows/create-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
steps:
2121

2222
- name: Checkout repository
23-
uses: actions/[email protected].0
23+
uses: actions/[email protected].1
2424
with:
2525
token: ${{ secrets.SBPAT }}
2626
persist-credentials: true

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: windows-latest
1313

1414
steps:
15-
- uses: actions/[email protected].0
15+
- uses: actions/[email protected].1
1616

1717
- name: Setup .NET
1818
uses: actions/[email protected]

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/[email protected].0
15+
- uses: actions/[email protected].1
1616
- name: Setup .NET
1717
uses: actions/[email protected]
1818
with:

.github/workflows/update-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout repository
16-
uses: actions/[email protected].0
16+
uses: actions/[email protected].1
1717
with:
1818
token: ${{ secrets.SBPAT }}
1919
persist-credentials: false

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [1.18.5] - 2023-10-19
10+
11+
### Changed
12+
13+
- Fixed a bug, where in `Append` overflows the internal buffer and throws an exception
14+
- Use better struct layout to be more cache friendly
15+
916
## [1.18.4] - 2023-10-14
1017

1118
### Changed
@@ -367,7 +374,9 @@ This release brings extensions to the `ValueStringBuilder` API. For `v1.0` the `
367374

368375
- Initial release
369376

370-
[Unreleased]: https://github.com/linkdotnet/StringBuilder/compare/1.18.4...HEAD
377+
[Unreleased]: https://github.com/linkdotnet/StringBuilder/compare/1.18.5...HEAD
378+
379+
[1.18.5]: https://github.com/linkdotnet/StringBuilder/compare/1.18.4...1.18.5
371380

372381
[1.18.4]: https://github.com/linkdotnet/StringBuilder/compare/1.18.3...1.18.4
373382

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ public void Append(bool value)
1414
{
1515
// 5 is the length of the string "False"
1616
// So we can check if we have enough space in the buffer
17-
if (bufferPosition + 5 > buffer.Length)
17+
var newSize = bufferPosition + 5;
18+
if (newSize > buffer.Length)
1819
{
19-
Grow(bufferPosition);
20+
Grow(newSize);
2021
}
2122

2223
if (!value.TryFormat(buffer[bufferPosition..], out var charsWritten))
@@ -105,9 +106,10 @@ public void AppendLine(scoped ReadOnlySpan<char> str)
105106
private void AppendSpanFormattable<T>(T value, ReadOnlySpan<char> format = default, int bufferSize = 36)
106107
where T : ISpanFormattable
107108
{
108-
if (bufferSize + bufferPosition >= Capacity)
109+
var newSize = bufferSize + bufferPosition;
110+
if (newSize >= Capacity)
109111
{
110-
Grow(bufferSize + bufferPosition);
112+
Grow(newSize);
111113
}
112114

113115
if (!value.TryFormat(buffer[bufferPosition..], out var written, format, null))

src/LinkDotNet.StringBuilder/ValueStringBuilder.Enumerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ public ref partial struct ValueStringBuilder
1111
[StructLayout(LayoutKind.Auto)]
1212
public ref struct Enumerator
1313
{
14-
private readonly Span<char> span;
14+
private readonly ReadOnlySpan<char> span;
1515
private int index;
1616

1717
/// <summary>Initializes a new instance of the <see cref="Enumerator"/> struct.</summary>
1818
/// <param name="span">The span to enumerate.</param>
1919
[MethodImpl(MethodImplOptions.AggressiveInlining)]
20-
internal Enumerator(Span<char> span)
20+
internal Enumerator(ReadOnlySpan<char> span)
2121
{
2222
this.span = span;
2323
index = -1;
2424
}
2525

2626
/// <summary>Gets the element at the current position of the enumerator.</summary>
27-
public readonly ref char Current
27+
public readonly char Current
2828
{
2929
[MethodImpl(MethodImplOptions.AggressiveInlining)]
30-
get => ref span[index];
30+
get => span[index];
3131
}
3232

3333
/// <summary>Advances the enumerator to the next element of the span.</summary>

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace LinkDotNet.StringBuilder;
1111
/// The <see cref="ValueStringBuilder"/> is declared as ref struct which brings certain limitations with it.
1212
/// You can only use it in another ref struct or as a local variable.
1313
/// </remarks>
14-
[StructLayout(LayoutKind.Auto)]
14+
[StructLayout(LayoutKind.Sequential)]
1515
[SkipLocalsInit]
1616
public ref partial struct ValueStringBuilder
1717
{

tests/LinkDotNet.StringBuilder.Benchmarks/AppendValueTypesBenchmark.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AppendValueTypes
88
private const int NumberOfIterations = 25;
99

1010
[Benchmark]
11-
public string DotNetStringBuilder()
11+
public string DotNetStringBuilderAppendValue()
1212
{
1313
var builder = new System.Text.StringBuilder();
1414

@@ -24,4 +24,22 @@ public string DotNetStringBuilder()
2424

2525
return builder.ToString();
2626
}
27+
28+
[Benchmark]
29+
public string ValueStringBuilderAppendValue()
30+
{
31+
using var builder = new ValueStringBuilder();
32+
33+
for (var i = 0; i < NumberOfIterations; i++)
34+
{
35+
builder.Append(true);
36+
builder.Append(int.MaxValue);
37+
builder.Append(decimal.MaxValue);
38+
builder.Append(byte.MinValue);
39+
builder.Append(float.Epsilon);
40+
builder.Append(double.Epsilon);
41+
}
42+
43+
return builder.ToString();
44+
}
2745
}

0 commit comments

Comments
 (0)