Skip to content

Commit 4084d05

Browse files
committed
feat: added initial size
1 parent cc67d98 commit 4084d05

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
66

77
## [Unreleased]
88

9+
### Added
10+
- New ctor that accepts an initial size
11+
912
## [1.19.1] - 2024-04-19
1013

1114
### Changed

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public ValueStringBuilder(ReadOnlySpan<char> initialText)
5555
Append(initialText);
5656
}
5757

58+
/// <summary>
59+
/// Initializes a new instance of the <see cref="ValueStringBuilder"/> struct.
60+
/// </summary>
61+
/// <param name="initialCapacity">The initial capacity that will be allocated for this instance.</param>
62+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
63+
public ValueStringBuilder(int initialCapacity)
64+
{
65+
Grow(initialCapacity);
66+
}
67+
5868
/// <summary>
5969
/// Gets the current length of the represented string.
6070
/// </summary>

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilderTests.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,20 @@ public void GivenAString_WhenEnumerating_ThenShouldReturnCharacters()
505505
}
506506

507507
[Fact]
508-
public void GivenStringBuilder_WhenDisposed_ThenEmtpyStringReturned()
508+
public void GivenStringBuilder_WhenDisposed_ThenEmptyStringReturned()
509509
{
510510
var builder = new ValueStringBuilder("Hello World");
511511

512512
builder.Dispose();
513513

514514
builder.ToString().Should().Be(string.Empty);
515515
}
516+
517+
[Fact]
518+
public void ShouldInitializeWithCapacity()
519+
{
520+
using var builder = new ValueStringBuilder(128);
521+
522+
builder.Capacity.Should().Be(128);
523+
}
516524
}

0 commit comments

Comments
 (0)