Skip to content

Commit 13473a1

Browse files
committed
[Array] add count field.
1 parent c789e55 commit 13473a1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/StructLinq/Array/ArrayEnumerable.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@ public struct ArrayEnumerable<T> : IStructCollection<T, ArrayStructEnumerator<T>
99
private readonly T[] array;
1010
private int length;
1111
private int start;
12+
private int count;
1213
#endregion
14+
1315
public ArrayEnumerable(T[] array, int start, int length)
1416
{
1517
this.array = array;
1618
this.length = length;
1719
this.start = start;
20+
count = length - start;
1821
}
1922

2023
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2124
public readonly ArrayStructEnumerator<T> GetEnumerator()
2225
{
23-
return new ArrayStructEnumerator<T>(array, start, Count);
26+
return new ArrayStructEnumerator<T>(array, start, count);
2427
}
2528

2629
public readonly int Count
2730
{
2831
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29-
get => MathHelpers.Max(0, length - start);
32+
get => count;
3033
}
3134

3235
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -36,7 +39,10 @@ public void Slice(uint start, uint? length)
3639
{
3740
this.start = (int)start + this.start;
3841
if (length.HasValue)
42+
{
3943
this.length = MathHelpers.Min((int)length.Value + this.start, this.length);
44+
count = MathHelpers.Max(0, this.length - this.start);
45+
}
4046
}
4147
}
4248

0 commit comments

Comments
 (0)