Skip to content

Commit 9121373

Browse files
committed
[Array] reduce some constraint and improve performance.
1 parent c3e152a commit 9121373

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/StructLinq/Array/ArrayStructEnumerator.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,18 @@ public struct ArrayStructEnumerator<T> : IEnumerator<T>
1414
public ArrayStructEnumerator(ref T[] array)
1515
{
1616
this.array = array;
17-
endIndex = array.Length;
18-
index = 0;
19-
Current = default;
17+
endIndex = array.Length - 1;
18+
index = -1;
2019
}
2120
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2221
public bool MoveNext()
2322
{
24-
if (index >= endIndex)
25-
return false;
26-
Current = array[index];
27-
++index;
28-
return true;
23+
return ++index <= endIndex;
2924
}
3025
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3126
public void Reset()
3227
{
33-
index = 0;
34-
Current = default;
28+
index = -1;
3529
}
3630
object IEnumerator.Current => Current;
3731

@@ -42,8 +36,7 @@ public void Dispose()
4236
public T Current
4337
{
4438
[MethodImpl(MethodImplOptions.AggressiveInlining)]
45-
get;
46-
private set;
39+
get => array[index];
4740
}
4841
}
4942
}

0 commit comments

Comments
 (0)