Skip to content

Commit 1abeff6

Browse files
committed
Mark more members as 'readonly'
1 parent 3541038 commit 1abeff6

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

src/CommunityToolkit.HighPerformance/Buffers/StringPool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public FixedSizePriorityMap(int capacity)
376376
/// <summary>
377377
/// Gets an <see cref="object"/> that can be used to synchronize access to the current instance.
378378
/// </summary>
379-
public object SyncRoot
379+
public readonly object SyncRoot
380380
{
381381
[MethodImpl(MethodImplOptions.AggressiveInlining)]
382382
get => this.buckets;
@@ -749,7 +749,7 @@ private void UpdateTimestamp(ref int heapIndex)
749749
/// a given number of nodes, those are all contiguous from the start of the array.
750750
/// </summary>
751751
[MethodImpl(MethodImplOptions.NoInlining)]
752-
private void UpdateAllTimestamps()
752+
private readonly void UpdateAllTimestamps()
753753
{
754754
int count = this.count;
755755
ref HeapEntry heapEntriesRef = ref this.heapEntries.DangerousGetReference();

src/CommunityToolkit.Mvvm.SourceGenerators/Helpers/HashCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private void Add(int value)
134134
/// Gets the resulting hashcode from the current instance.
135135
/// </summary>
136136
/// <returns>The resulting hashcode from the current instance.</returns>
137-
public int ToHashCode()
137+
public readonly int ToHashCode()
138138
{
139139
uint length = this.length;
140140
uint position = length % 4;
@@ -165,12 +165,12 @@ public int ToHashCode()
165165
/// <inheritdoc/>
166166
[Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes. Use ToHashCode to retrieve the computed hash code.", error: true)]
167167
[EditorBrowsable(EditorBrowsableState.Never)]
168-
public override int GetHashCode() => throw new NotSupportedException();
168+
public override readonly int GetHashCode() => throw new NotSupportedException();
169169

170170
/// <inheritdoc/>
171171
[Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes.", error: true)]
172172
[EditorBrowsable(EditorBrowsableState.Never)]
173-
public override bool Equals(object? obj) => throw new NotSupportedException();
173+
public override readonly bool Equals(object? obj) => throw new NotSupportedException();
174174

175175
/// <summary>
176176
/// Rotates the specified value left by the specified number of bits.

src/CommunityToolkit.Mvvm/Messaging/Internals/ArrayPoolBufferWriter{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static ArrayPoolBufferWriter<T> Create()
5858
/// <summary>
5959
/// Gets a <see cref="ReadOnlySpan{T}"/> with the current items.
6060
/// </summary>
61-
public ReadOnlySpan<T> Span
61+
public readonly ReadOnlySpan<T> Span
6262
{
6363
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6464
get => this.span.Slice(0, this.index);
@@ -116,7 +116,7 @@ private void ResizeBufferAndAdd(T item)
116116
}
117117

118118
/// <inheritdoc cref="IDisposable.Dispose"/>
119-
public void Dispose()
119+
public readonly void Dispose()
120120
{
121121
Array.Clear(this.array, 0, this.index);
122122

src/CommunityToolkit.Mvvm/Messaging/Internals/System/Collections.Generic/Dictionary2.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public bool MoveNext()
320320
/// Gets the current key.
321321
/// </summary>
322322
[MethodImpl(MethodImplOptions.AggressiveInlining)]
323-
public TKey GetKey()
323+
public readonly TKey GetKey()
324324
{
325325
return this.entries[this.index - 1].Key;
326326
}
@@ -329,7 +329,7 @@ public TKey GetKey()
329329
/// Gets the current value.
330330
/// </summary>
331331
[MethodImpl(MethodImplOptions.AggressiveInlining)]
332-
public TValue GetValue()
332+
public readonly TValue GetValue()
333333
{
334334
return this.entries[this.index - 1].Value!;
335335
}

src/CommunityToolkit.Mvvm/Messaging/Internals/System/Runtime.CompilerServices/ConditionalWeakTable2{TKey,TValue}.Proxy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public Enumerator(ConditionalWeakTable2<TKey, TValue> owner)
7272
}
7373

7474
/// <inheritdoc cref="IDisposable.Dispose"/>
75-
public void Dispose()
75+
public readonly void Dispose()
7676
{
7777
this.enumerator.Dispose();
7878
}
7979

8080
/// <inheritdoc cref="Collections.IEnumerator.MoveNext"/>
81-
public bool MoveNext()
81+
public readonly bool MoveNext()
8282
{
8383
return this.enumerator.MoveNext();
8484
}
@@ -87,7 +87,7 @@ public bool MoveNext()
8787
/// Gets the current key.
8888
/// </summary>
8989
[MethodImpl(MethodImplOptions.AggressiveInlining)]
90-
public TKey GetKey()
90+
public readonly TKey GetKey()
9191
{
9292
return this.enumerator.Current.Key;
9393
}
@@ -96,7 +96,7 @@ public TKey GetKey()
9696
/// Gets the current value.
9797
/// </summary>
9898
[MethodImpl(MethodImplOptions.AggressiveInlining)]
99-
public TValue GetValue()
99+
public readonly TValue GetValue()
100100
{
101101
return this.enumerator.Current.Value;
102102
}

src/CommunityToolkit.Mvvm/Messaging/Internals/System/Runtime.CompilerServices/ConditionalWeakTable2{TKey,TValue}.ZeroAlloc.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public bool MoveNext()
248248
/// Gets the current key.
249249
/// </summary>
250250
[MethodImpl(MethodImplOptions.AggressiveInlining)]
251-
public TKey GetKey()
251+
public readonly TKey GetKey()
252252
{
253253
return this.key!;
254254
}
@@ -257,7 +257,7 @@ public TKey GetKey()
257257
/// Gets the current value.
258258
/// </summary>
259259
[MethodImpl(MethodImplOptions.AggressiveInlining)]
260-
public TValue GetValue()
260+
public readonly TValue GetValue()
261261
{
262262
return this.value!;
263263
}

src/CommunityToolkit.Mvvm/Messaging/Internals/System/Runtime.CompilerServices/ConditionalWeakTable2{TKey,TValue}.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public Enumerator(ConditionalWeakTable2<TKey, TValue> owner)
139139
}
140140

141141
/// <inheritdoc cref="IDisposable.Dispose"/>
142-
public void Dispose()
142+
public readonly void Dispose()
143143
{
144144
}
145145

@@ -189,7 +189,7 @@ public bool MoveNext()
189189
/// Gets the current key.
190190
/// </summary>
191191
[MethodImpl(MethodImplOptions.AggressiveInlining)]
192-
public TKey GetKey()
192+
public readonly TKey GetKey()
193193
{
194194
return this.key!;
195195
}
@@ -198,7 +198,7 @@ public TKey GetKey()
198198
/// Gets the current value.
199199
/// </summary>
200200
[MethodImpl(MethodImplOptions.AggressiveInlining)]
201-
public TValue GetValue()
201+
public readonly TValue GetValue()
202202
{
203203
return this.value!;
204204
}

tests/CommunityToolkit.HighPerformance.UnitTests/Helpers/Test_ObjectMarshal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal struct TestStruct : IEquatable<TestStruct>
7070
public string Text;
7171

7272
/// <inheritdoc/>
73-
public bool Equals(TestStruct other)
73+
public readonly bool Equals(TestStruct other)
7474
{
7575
return
7676
this.Number == other.Number &&

tests/CommunityToolkit.HighPerformance.UnitTests/Test_Box{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal struct TestStruct : IEquatable<TestStruct>
3636
public string Text;
3737

3838
/// <inheritdoc/>
39-
public bool Equals(TestStruct other)
39+
public readonly bool Equals(TestStruct other)
4040
{
4141
return
4242
this.Number == other.Number &&

0 commit comments

Comments
 (0)