Skip to content

Commit

Permalink
feat: added initial size
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed May 2, 2024
1 parent cc67d98 commit 4084d05
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T

## [Unreleased]

### Added
- New ctor that accepts an initial size

## [1.19.1] - 2024-04-19

### Changed
Expand Down
10 changes: 10 additions & 0 deletions src/LinkDotNet.StringBuilder/ValueStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public ValueStringBuilder(ReadOnlySpan<char> initialText)
Append(initialText);
}

/// <summary>
/// Initializes a new instance of the <see cref="ValueStringBuilder"/> struct.
/// </summary>
/// <param name="initialCapacity">The initial capacity that will be allocated for this instance.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ValueStringBuilder(int initialCapacity)
{
Grow(initialCapacity);
}

/// <summary>
/// Gets the current length of the represented string.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,20 @@ public void GivenAString_WhenEnumerating_ThenShouldReturnCharacters()
}

[Fact]
public void GivenStringBuilder_WhenDisposed_ThenEmtpyStringReturned()
public void GivenStringBuilder_WhenDisposed_ThenEmptyStringReturned()
{
var builder = new ValueStringBuilder("Hello World");

builder.Dispose();

builder.ToString().Should().Be(string.Empty);
}

[Fact]
public void ShouldInitializeWithCapacity()
{
using var builder = new ValueStringBuilder(128);

builder.Capacity.Should().Be(128);
}
}

0 comments on commit 4084d05

Please sign in to comment.