Skip to content

Commit 40a2e76

Browse files
authored
Make ArrayPoolExtensions public (#384)
1 parent d62f946 commit 40a2e76

File tree

11 files changed

+66
-12
lines changed

11 files changed

+66
-12
lines changed

NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ readonly object? IEnumerator.Current
131131

132132
[MethodImpl(MethodImplOptions.AggressiveInlining)]
133133
public bool MoveNext()
134-
=> ++index < source.Count;
134+
{
135+
if (index < source.Count)
136+
{
137+
index++;
138+
return index < source.Count;
139+
}
140+
return false;
141+
}
135142

136143
[MethodImpl(MethodImplOptions.AggressiveInlining)]
137144
[ExcludeFromCodeCoverage]

NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ readonly object? IEnumerator.Current
7878
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7979
public bool MoveNext()
8080
{
81+
var index = this.index;
8182
while (++index <= end)
8283
{
8384
if (predicate.Invoke(source![index]))
85+
{
86+
this.index = index;
8487
return true;
88+
}
8589
}
8690
return false;
8791
}

NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ readonly object? IEnumerator.Current
7777
public bool MoveNext()
7878
{
7979
var span = source.Span;
80+
var index = this.index;
8081
while (++index < span.Length)
8182
{
8283
var item = span[index];
8384
if (predicate.Invoke(item))
85+
{
86+
this.index = index;
8487
return true;
88+
}
8589
}
8690
return false;
8791
}

NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@ readonly object? IEnumerator.Current
8484
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8585
public bool MoveNext()
8686
{
87+
var index = this.index;
8788
while (++index <= end)
8889
{
8990
if (predicate.Invoke(source![index + offset], index))
91+
{
92+
this.index = index;
9093
return true;
94+
}
9195
}
9296
return false;
9397
}

NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,14 @@ readonly object? IEnumerator.Current
8282
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8383
public bool MoveNext()
8484
{
85+
var index = this.index;
8586
while (++index <= end)
8687
{
8788
if (predicate.Invoke(source![index]))
89+
{
90+
this.index = index;
8891
return true;
92+
}
8993
}
9094
return false;
9195
}

NetFabric.Hyperlinq/Lease.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed class Lease<T>
2828
T[]? rented;
2929
int length;
3030

31-
public Lease(ArrayPool<T> pool, int length, bool clearOnDispose = false)
31+
internal Lease(ArrayPool<T> pool, int length, bool clearOnDispose)
3232
{
3333
Debug.Assert(length >= 0);
3434

@@ -37,7 +37,7 @@ public Lease(ArrayPool<T> pool, int length, bool clearOnDispose = false)
3737
this.clearOnDispose = clearOnDispose;
3838
rented = length is 0
3939
? Array.Empty<T>()
40-
: this.pool.Rent(length);
40+
: pool.Rent(length);
4141
}
4242

4343
/// <summary>
@@ -163,7 +163,12 @@ public readonly T Current
163163

164164
[MethodImpl(MethodImplOptions.AggressiveInlining)]
165165
public bool MoveNext()
166-
=> ++index < length;
166+
{
167+
if (index >= length)
168+
return false;
169+
index++;
170+
return index < length;
171+
}
167172
}
168173

169174
public struct DisposableEnumerator
@@ -192,7 +197,12 @@ readonly object? IEnumerator.Current
192197

193198
[MethodImpl(MethodImplOptions.AggressiveInlining)]
194199
public bool MoveNext()
195-
=> ++index < length;
200+
{
201+
if (index >= length)
202+
return false;
203+
index++;
204+
return index < length;
205+
}
196206

197207
public void Reset()
198208
=> index = -1;

NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PackageId>NetFabric.Hyperlinq</PackageId>
66
<Title>NetFabric.Hyperlinq</Title>
77
<Description> High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, Memory, and Span.</Description>
8-
<Version>3.0.0-beta47</Version>
8+
<Version>3.0.0-beta48</Version>
99
<PackageIcon>Icon.png</PackageIcon>
1010
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1111
<PackageTags>netfabric, hyperlinq, linq, enumeration, extensions, performance</PackageTags>

NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ public TResult Current
133133

134134
[MethodImpl(MethodImplOptions.AggressiveInlining)]
135135
public bool MoveNext()
136-
=> ++index <= end;
136+
{
137+
if (index <= end)
138+
{
139+
index++;
140+
return index <= end;
141+
}
142+
return false;
143+
}
137144

138145
[ExcludeFromCodeCoverage]
139146
[DoesNotReturn]

NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,15 @@ public TResult Current
125125

126126
[MethodImpl(MethodImplOptions.AggressiveInlining)]
127127
public bool MoveNext()
128-
=> ++index <= end;
129-
128+
{
129+
if (index <= end)
130+
{
131+
index++;
132+
return index <= end;
133+
}
134+
return false;
135+
}
136+
130137
[ExcludeFromCodeCoverage]
131138
[DoesNotReturn]
132139
public readonly void Reset()

NetFabric.Hyperlinq/Set/Distinct/Distinct.ArraySegment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ readonly object? IEnumerator.Current
6767
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6868
public bool MoveNext()
6969
{
70+
var index = this.index;
7071
while (++index <= end)
7172
{
7273
if (set.Add(source![index]))
74+
{
75+
this.index = index;
7376
return true;
77+
}
7478
}
7579
return false;
7680
}

0 commit comments

Comments
 (0)