Skip to content

Commit 67246e5

Browse files
committed
Added more readonly hints
1 parent 5c8fd2e commit 67246e5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace LinkDotNet.StringBuilder;
1212
/// You can only use it in another ref struct or as a local variable.
1313
/// </remarks>
1414
[StructLayout(LayoutKind.Auto)]
15+
[SkipLocalsInit]
1516
public ref partial struct ValueStringBuilder
1617
{
1718
private int bufferPosition;
@@ -68,13 +69,13 @@ public ValueStringBuilder(ReadOnlySpan<char> initialText)
6869
/// <value>
6970
/// The current maximum capacity before growing the array.
7071
/// </value>
71-
public int Capacity => buffer.Length;
72+
public readonly int Capacity => buffer.Length;
7273

7374
/// <summary>
7475
/// Returns the character at the given index or throws an <see cref="IndexOutOfRangeException"/> if the index is bigger than the string.
7576
/// </summary>
7677
/// <param name="index">Index position, which should be retrieved.</param>
77-
public ref char this[int index] => ref buffer[index];
78+
public readonly ref char this[int index] => ref buffer[index];
7879

7980
/// <summary>
8081
/// Creates a <see cref="string"/> instance from that builder.
@@ -104,7 +105,7 @@ public ValueStringBuilder(ReadOnlySpan<char> initialText)
104105
/// </code>
105106
/// </remarks>
106107
[MethodImpl(MethodImplOptions.AggressiveInlining)]
107-
public ref char GetPinnableReference() => ref MemoryMarshal.GetReference(buffer);
108+
public readonly ref char GetPinnableReference() => ref MemoryMarshal.GetReference(buffer);
108109

109110
/// <summary>
110111
/// Tries to copy the represented string into the given <see cref="Span{T}"/>.
@@ -121,10 +122,7 @@ public ValueStringBuilder(ReadOnlySpan<char> initialText)
121122
/// This will not enforce some re-allocation or shrinking of the internal buffer. The size stays the same.
122123
/// </remarks>
123124
[MethodImpl(MethodImplOptions.AggressiveInlining)]
124-
public void Clear()
125-
{
126-
bufferPosition = 0;
127-
}
125+
public void Clear() => bufferPosition = 0;
128126

129127
/// <summary>
130128
/// Ensures that the builder has at least <paramref name="newCapacity"/> amount of capacity.

0 commit comments

Comments
 (0)