Skip to content

Commit f2c42cf

Browse files
committed
Added readonly hint on methods
1 parent 1af3382 commit f2c42cf

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
1010

1111
- Added overload which allows an initial string for the ValueStringBuilder
1212
- Meziantou.Analyzer as developer dependency to spot issues early on
13+
- `readonly` hint's on readonly methods
1314

1415
### Changed
1516
- Added `StructLayout(LayoutKind.Auto)`, which makes the ValueStringBuilder not usable for unmanaged code

src/LinkDotNet.StringBuilder/TypedSpanList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public TypedSpanList()
2525
}
2626

2727
[MethodImpl(MethodImplOptions.AggressiveInlining)]
28-
public ReadOnlySpan<T> AsSpan() => buffer[..count];
28+
public readonly ReadOnlySpan<T> AsSpan() => buffer[..count];
2929

3030
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3131
public void Add(T value)

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ public ValueStringBuilder(ReadOnlySpan<char> initialText)
8181
/// </summary>
8282
/// <returns>The <see cref="string"/> instance.</returns>
8383
[MethodImpl(MethodImplOptions.AggressiveInlining)]
84-
public override string ToString() => new(buffer[..bufferPosition]);
84+
public readonly override string ToString() => new(buffer[..bufferPosition]);
8585

8686
/// <summary>
8787
/// Returns the string as an <see cref="ReadOnlySpan{T}"/>.
8888
/// </summary>
8989
/// <returns>The filled array as <see cref="ReadOnlySpan{T}"/>.</returns>
9090
[MethodImpl(MethodImplOptions.AggressiveInlining)]
91-
public ReadOnlySpan<char> AsSpan() => buffer[..bufferPosition];
91+
public readonly ReadOnlySpan<char> AsSpan() => buffer[..bufferPosition];
9292

9393
/// <summary>
9494
/// Get a pinnable reference to the represented string from this builder.
@@ -112,7 +112,7 @@ public ValueStringBuilder(ReadOnlySpan<char> initialText)
112112
/// <param name="destination">The destination where the internal string is copied into.</param>
113113
/// <returns>True, if the copy was successful, otherwise false.</returns>
114114
[MethodImpl(MethodImplOptions.AggressiveInlining)]
115-
public bool TryCopyTo(Span<char> destination) => buffer[..bufferPosition].TryCopyTo(destination);
115+
public readonly bool TryCopyTo(Span<char> destination) => buffer[..bufferPosition].TryCopyTo(destination);
116116

117117
/// <summary>
118118
/// Clears the internal representation of the string.
@@ -189,7 +189,7 @@ public void Remove(int startIndex, int length)
189189
/// <param name="word">Word to look for in this string.</param>
190190
/// <returns>The index of the found <paramref name="word"/> in this string or -1 if not found.</returns>
191191
[MethodImpl(MethodImplOptions.AggressiveInlining)]
192-
public int IndexOf(ReadOnlySpan<char> word) => IndexOf(word, 0);
192+
public readonly int IndexOf(ReadOnlySpan<char> word) => IndexOf(word, 0);
193193

194194
/// <summary>
195195
/// Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
@@ -198,7 +198,7 @@ public void Remove(int startIndex, int length)
198198
/// <param name="startIndex">Index to begin with.</param>
199199
/// <returns>The index of the found <paramref name="word"/> in this string or -1 if not found.</returns>
200200
[MethodImpl(MethodImplOptions.AggressiveInlining)]
201-
public int IndexOf(ReadOnlySpan<char> word, int startIndex)
201+
public readonly int IndexOf(ReadOnlySpan<char> word, int startIndex)
202202
{
203203
if (startIndex < 0)
204204
{
@@ -219,7 +219,7 @@ public int IndexOf(ReadOnlySpan<char> word, int startIndex)
219219
/// <param name="word">Word to look for in this string.</param>
220220
/// <returns>The index of the found <paramref name="word"/> in this string or -1 if not found.</returns>
221221
[MethodImpl(MethodImplOptions.AggressiveInlining)]
222-
public int LastIndexOf(ReadOnlySpan<char> word) => LastIndexOf(word, 0);
222+
public readonly int LastIndexOf(ReadOnlySpan<char> word) => LastIndexOf(word, 0);
223223

224224
/// <summary>
225225
/// Returns the index within this string of the last occurrence of the specified substring, starting at the specified index.
@@ -228,7 +228,7 @@ public int IndexOf(ReadOnlySpan<char> word, int startIndex)
228228
/// <param name="startIndex">Index to begin with.</param>
229229
/// <returns>The index of the found <paramref name="word"/> in this string or -1 if not found.</returns>
230230
[MethodImpl(MethodImplOptions.AggressiveInlining)]
231-
public int LastIndexOf(ReadOnlySpan<char> word, int startIndex)
231+
public readonly int LastIndexOf(ReadOnlySpan<char> word, int startIndex)
232232
{
233233
if (startIndex < 0)
234234
{
@@ -252,13 +252,13 @@ public int LastIndexOf(ReadOnlySpan<char> word, int startIndex)
252252
/// This method performs an ordinal (case-sensitive and culture-insensitive) comparison.
253253
/// </remarks>
254254
[MethodImpl(MethodImplOptions.AggressiveInlining)]
255-
public bool Contains(ReadOnlySpan<char> word) => IndexOf(word) != -1;
255+
public readonly bool Contains(ReadOnlySpan<char> word) => IndexOf(word) != -1;
256256

257257
/// <summary>
258258
/// Disposes the instance and returns rented buffer from an array pool if needed.
259259
/// </summary>
260260
[MethodImpl(MethodImplOptions.AggressiveInlining)]
261-
public void Dispose()
261+
public readonly void Dispose()
262262
{
263263
if (arrayFromPool != null)
264264
{

0 commit comments

Comments
 (0)