-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathArrayEnumerator.cs
41 lines (34 loc) · 1.06 KB
/
ArrayEnumerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Runtime.CompilerServices;
namespace Plato
{
public struct ArrayEnumerator<T> : IEnumerator<T>
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ArrayEnumerator(IArray<T> array)
{
Array = array;
Index = -1;
Count = array.Count;
}
public readonly IArray<T> Array;
public int Index;
public readonly int Count;
public T Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Array[Index];
}
object IEnumerator.Current
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Current;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose() { }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool MoveNext() => ++Index < Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Reset() => Index = -1;
}
}