Skip to content

Commit 3d94ead

Browse files
committed
[Skip] Optimize Skip for IRefStructCollection
1 parent a1f45c0 commit 3d94ead

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/StructLinq.Tests/RefSkipTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
using System.Linq;
22
using StructLinq.Array;
33
using StructLinq.Skip;
4+
using StructLinq.Where;
45
using Xunit;
56

67
namespace StructLinq.Tests
78
{
89
public class RefSkipTests : AbstractRefEnumerableTests<int,
9-
RefSkipEnumerable<int, ArrayRefEnumerable<int>, ArrayRefStructEnumerator<int>>,
10-
RefSkipEnumerator<int, ArrayRefStructEnumerator<int>>>
10+
RefSkipEnumerable<int, RefWhereEnumerable<int, ArrayRefEnumerable<int>, ArrayRefStructEnumerator<int>, StructInFunction<int, bool>>, RefWhereEnumerator<int, ArrayRefStructEnumerator<int>, StructInFunction<int, bool>>> ,
11+
RefSkipEnumerator<int, RefWhereEnumerator<int, ArrayRefStructEnumerator<int>, StructInFunction<int, bool>>>>
1112
{
12-
protected override RefSkipEnumerable<int, ArrayRefEnumerable<int>, ArrayRefStructEnumerator<int>> Build(int size)
13+
protected override RefSkipEnumerable<int, RefWhereEnumerable<int, ArrayRefEnumerable<int>, ArrayRefStructEnumerator<int>, StructInFunction<int, bool>>, RefWhereEnumerator<int, ArrayRefStructEnumerator<int>, StructInFunction<int, bool>>> Build(int size)
1314
{
14-
return StructEnumerable.Range(-1, size + 5).ToArray().ToRefStructEnumerable().Skip(5, x=> x);
15-
15+
var refSkipEnumerable = StructEnumerable.Range(-1, size + 5).ToArray().ToRefStructEnumerable().Where((in int x) => true, x=>x).Skip(5, x=> x);
16+
return refSkipEnumerable;
1617
}
1718

1819
[Theory]

src/StructLinq/Skip/StructCollection.Skip.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,24 @@ public static IStructCollection<T, TEnumerator> Skip<T, TEnumerator>(this IStruc
2424
newCollection.Slice(count, null);
2525
return newCollection;
2626
}
27+
28+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
public static TStructCollection Skip<T,TStructCollection, TEnumerator>(this TStructCollection collection, uint count, Func<TStructCollection, IRefStructCollection<T, TEnumerator>> _)
30+
where TEnumerator : struct, IRefStructEnumerator<T>
31+
where TStructCollection : struct, IRefStructCollection<T, TEnumerator>
32+
{
33+
var newCollection = collection;
34+
newCollection.Slice(count, null);
35+
return newCollection;
36+
}
37+
38+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
39+
public static IRefStructCollection<T, TEnumerator> Skip<T, TEnumerator>(this IRefStructCollection<T, TEnumerator> collection, uint count)
40+
where TEnumerator : struct, IRefStructEnumerator<T>
41+
{
42+
var newCollection = (IRefStructCollection<T, TEnumerator>)collection.Clone();
43+
newCollection.Slice(count, null);
44+
return newCollection;
45+
}
2746
}
2847
}

0 commit comments

Comments
 (0)