Skip to content

Commit 1438e39

Browse files
committed
Added more readonly modifiers to enumerators
1 parent 54acdb3 commit 1438e39

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.ComponentModel;
8+
using System.Diagnostics.Contracts;
89
using System.Runtime.CompilerServices;
910
using System.Runtime.InteropServices;
1011

@@ -42,8 +43,9 @@ public ReadOnlySpanEnumerable(ReadOnlySpan<T> span)
4243
/// Implements the duck-typed <see cref="IEnumerable{T}.GetEnumerator"/> method.
4344
/// </summary>
4445
/// <returns>An <see cref="ReadOnlySpanEnumerable{T}"/> instance targeting the current <see cref="ReadOnlySpan{T}"/> value.</returns>
46+
[Pure]
4547
[MethodImpl(MethodImplOptions.AggressiveInlining)]
46-
public ReadOnlySpanEnumerable<T> GetEnumerator() => this;
48+
public readonly ReadOnlySpanEnumerable<T> GetEnumerator() => this;
4749

4850
/// <summary>
4951
/// Implements the duck-typed <see cref="System.Collections.IEnumerator.MoveNext"/> method.
@@ -67,7 +69,7 @@ public bool MoveNext()
6769
/// <summary>
6870
/// Gets the duck-typed <see cref="IEnumerator{T}.Current"/> property.
6971
/// </summary>
70-
public Item Current
72+
public readonly Item Current
7173
{
7274
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7375
get

Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.ComponentModel;
8+
using System.Diagnostics.Contracts;
89
using System.Runtime.CompilerServices;
910

1011
namespace Microsoft.Toolkit.HighPerformance.Enumerables
@@ -54,8 +55,9 @@ public ReadOnlySpanTokenizer(ReadOnlySpan<T> span, T separator)
5455
/// Implements the duck-typed <see cref="IEnumerable{T}.GetEnumerator"/> method.
5556
/// </summary>
5657
/// <returns>An <see cref="ReadOnlySpanTokenizer{T}"/> instance targeting the current <see cref="ReadOnlySpan{T}"/> value.</returns>
58+
[Pure]
5759
[MethodImpl(MethodImplOptions.AggressiveInlining)]
58-
public ReadOnlySpanTokenizer<T> GetEnumerator() => this;
60+
public readonly ReadOnlySpanTokenizer<T> GetEnumerator() => this;
5961

6062
/// <summary>
6163
/// Implements the duck-typed <see cref="System.Collections.IEnumerator.MoveNext"/> method.
@@ -94,7 +96,7 @@ public bool MoveNext()
9496
/// <summary>
9597
/// Gets the duck-typed <see cref="IEnumerator{T}.Current"/> property.
9698
/// </summary>
97-
public ReadOnlySpan<T> Current
99+
public readonly ReadOnlySpan<T> Current
98100
{
99101
[MethodImpl(MethodImplOptions.AggressiveInlining)]
100102
get => this.span.Slice(this.start, this.end - this.start);

Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.ComponentModel;
8+
using System.Diagnostics.Contracts;
89
using System.Runtime.CompilerServices;
910
using System.Runtime.InteropServices;
1011

@@ -42,8 +43,9 @@ public SpanEnumerable(Span<T> span)
4243
/// Implements the duck-typed <see cref="IEnumerable{T}.GetEnumerator"/> method.
4344
/// </summary>
4445
/// <returns>An <see cref="SpanEnumerable{T}"/> instance targeting the current <see cref="Span{T}"/> value.</returns>
46+
[Pure]
4547
[MethodImpl(MethodImplOptions.AggressiveInlining)]
46-
public SpanEnumerable<T> GetEnumerator() => this;
48+
public readonly SpanEnumerable<T> GetEnumerator() => this;
4749

4850
/// <summary>
4951
/// Implements the duck-typed <see cref="System.Collections.IEnumerator.MoveNext"/> method.
@@ -67,7 +69,7 @@ public bool MoveNext()
6769
/// <summary>
6870
/// Gets the duck-typed <see cref="IEnumerator{T}.Current"/> property.
6971
/// </summary>
70-
public Item Current
72+
public readonly Item Current
7173
{
7274
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7375
get

Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.ComponentModel;
8+
using System.Diagnostics.Contracts;
89
using System.Runtime.CompilerServices;
910

1011
namespace Microsoft.Toolkit.HighPerformance.Enumerables
@@ -54,8 +55,9 @@ public SpanTokenizer(Span<T> span, T separator)
5455
/// Implements the duck-typed <see cref="IEnumerable{T}.GetEnumerator"/> method.
5556
/// </summary>
5657
/// <returns>An <see cref="SpanTokenizer{T}"/> instance targeting the current <see cref="Span{T}"/> value.</returns>
58+
[Pure]
5759
[MethodImpl(MethodImplOptions.AggressiveInlining)]
58-
public SpanTokenizer<T> GetEnumerator() => this;
60+
public readonly SpanTokenizer<T> GetEnumerator() => this;
5961

6062
/// <summary>
6163
/// Implements the duck-typed <see cref="System.Collections.IEnumerator.MoveNext"/> method.
@@ -94,7 +96,7 @@ public bool MoveNext()
9496
/// <summary>
9597
/// Gets the duck-typed <see cref="IEnumerator{T}.Current"/> property.
9698
/// </summary>
97-
public Span<T> Current
99+
public readonly Span<T> Current
98100
{
99101
[MethodImpl(MethodImplOptions.AggressiveInlining)]
100102
get => this.span.Slice(this.start, this.end - this.start);

0 commit comments

Comments
 (0)